1.0.5 • Published 1 year ago

mister-crud-lite v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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:

  1. The data you want to store in the db
  2. The mongodb model
  3. Required Fields Array
  4. 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:

  1. The fieldName
  2. The fieldValue
  3. 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:

  1. The data you want to update
  2. Id of the item
  3. The mongodb model
  4. 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:

  1. Id of the item
  2. 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}

Authors

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago