mister-crud-lite
v1.0.5
Published
This is the crud library to make it easy for developers to perform some crud operations
Downloads
2
Readme
v1.0.5:
- Fixed updateItem function uniqueCheck
v1.0.4
Note:
It's only workable with Mongodb
mister-crud-lite
It simplifies basic database operations. Create, read, update, and delete documents with ease using concise and intuitive methods.
Installation
Install mister-crud-lite with npm
npm i mister-crud-lite
Features
- Create Items
- Read Items
- Update Items
- Delete Items
Usage/Examples
import {
createItem,
deleteItem,
getItems,
getItemsByField,
updateItem,
} from "mister-crud-lite";
Creating Item
The createItem function takes four arguments:
- The data you want to store in the db
- The mongodb model
- Required Fields Array
- Unique Fields Array
Note:
Last Two arguments are optional
const createResp = await createItem(
{ name: "yourName", className: "yourClassName" },
MyMongoModel,
["name", "className"],
["name"]
);
console.log(createResp);
// {success:boolean, message:string, statusCode:number, newItem:object}
Reading Items
The getItems function takes only one argument:
- The mongodb model
const getResp = await getItems(MyMongoModel);
console.log(getResp);
// {success:boolean, message:string, statusCode:number, items:array}
The getItemsByField function takes 3 arguments:
- The fieldName
- The fieldValue
- The mongodbModel
const getByFieldResp = await getItems("name", "yourName", MyMongoModel);
console.log(getResp);
// {success:boolean, message:string, statusCode:number, items:array}
Updating Item
The updateItem function takes four arguments:
- The data you want to update
- Id of the item
- The mongodb model
- Unique Fields Array
Note:
Last Two arguments are optional
const updateResp = await updateItem({ name: "changedName" }, id, MyItems, [
"name",
]);
console.log(updateResp);
// {success:boolean, message:string, statusCode:number, updatedItem:object}
Deleting Item
The deleteItem function takes 2 arguments:
- Id of the item
- The mongodb model
Note:
Last Two arguments are optional
const deleteResp = await deleteItem(id, MyItems);
console.log(deleteResp);
// {success:boolean, message:string, statusCode:number, id:string}