All Projects → graph-land → quick-crud

graph-land / quick-crud

Licence: MIT License
An easy CRUD operation based on Factory pattern with Mongoose.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to quick-crud

Queryql
Easily add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string!
Stars: ✭ 76 (+375%)
Mutual labels:  pagination, orm
Mongoengine
MongoEngine is a Python Object-Document Mapper for working with MongoDB. Documentation is available at https://mongoengine-odm.readthedocs.io - there is currently a tutorial, a user guide, and an API reference.
Stars: ✭ 3,632 (+22600%)
Mutual labels:  orm, mongodb-orm
Sqlhelper
SQL Tools ( Dialect, Pagination, DDL dump, UrlParser, SqlStatementParser, WallFilter, BatchExecutor for Test) based Java. it is easy to integration into any ORM frameworks
Stars: ✭ 242 (+1412.5%)
Mutual labels:  pagination, orm
Prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite & MongoDB (Preview)
Stars: ✭ 18,168 (+113450%)
Mutual labels:  orm, mongodb-orm
fast-relay-pagination
Improve relay pagination performance with find and limit
Stars: ✭ 18 (+12.5%)
Mutual labels:  pagination, mongoose-pagination
ormdb
ORM tool for .Net / .Net.Core
Stars: ✭ 14 (-12.5%)
Mutual labels:  orm
fsharp-dapper
The wrapper above the 'Dapper' library allows you to write more familiar code in the F # language. It also contains a functional for more simple work with temporary tables
Stars: ✭ 72 (+350%)
Mutual labels:  orm
restjs
An “ORM” style library for consuming REST APIs on the frontend
Stars: ✭ 13 (-18.75%)
Mutual labels:  orm
gorm-hibernate5
GORM for Hibernate 5
Stars: ✭ 51 (+218.75%)
Mutual labels:  orm
react-crud-table
A table that includes all the CRUD operations.
Stars: ✭ 34 (+112.5%)
Mutual labels:  pagination
monalisa-orm
Very Simple ORM
Stars: ✭ 70 (+337.5%)
Mutual labels:  orm
MeowVapor
Meow plugin for API generation
Stars: ✭ 12 (-25%)
Mutual labels:  orm
sequelize-adapter
Sequelize adapter for Casbin
Stars: ✭ 51 (+218.75%)
Mutual labels:  orm
Sworm
CoreData based Swift ORM
Stars: ✭ 70 (+337.5%)
Mutual labels:  orm
gorm-cursor-paginator
A paginator doing cursor-based pagination based on GORM
Stars: ✭ 92 (+475%)
Mutual labels:  pagination
mongoose-graphql-pagination
GraphQL cursor pagination (Relay-like) for Mongoose models.
Stars: ✭ 29 (+81.25%)
Mutual labels:  pagination
goseed
Go + MongoDB rest api framework
Stars: ✭ 20 (+25%)
Mutual labels:  mongodb-orm
checkbox.sh
Interactive checkboxes (menu) with pagination and vim keybinds for bash
Stars: ✭ 26 (+62.5%)
Mutual labels:  pagination
pykeyboard
Best Keyboard and Pagination for the Pyrogram Library.
Stars: ✭ 42 (+162.5%)
Mutual labels:  pagination
doctrine-json-odm
JSON Object-Document Mapping bundle for Symfony and Doctrine
Stars: ✭ 15 (-6.25%)
Mutual labels:  orm

QuickCrud.js

Installation

npm i quick-crud

or

yarn add quick-crud

An easy CRUD operation based on Factory pattern with Mongoose. There are four CRUD operations we can do:

  • index({model, where, populateOptions, paginationOptions}) : Fetch all documents with pagination.

    • model - Mongoose model.
    • where - MongoDB filter object.
    • populateOptions - Mongoose population object/string.
    • paginationOptions can get three parameters.
      • limit:number - Resource count to show. Default is 10
      • page:number - Pagination page number. Default is 1.
      • sort:string - MongoDB property sort key. Default is '-createdAt'
  • store({model, data}) - You can create a doc and store it to MongoDB.

    • model - Mongoose model.
    • data - An object of data to store in MongoDB based on Mongoose Schema
  • show({model, where, populationOptions}): Fetch a single document via filter key.

    • model - Mongoose model.
    • where - MongoDB filter object.
    • populateOptions - Mongoose population object/string.
  • update({model, where, data}) - updates the first document that matches where. data is the object where you want to update the data.

    • model - Mongoose model.
    • where - MongoDB filter object.
    • data - An object of data to update that matches with where filter key(s).
  • destroy({model, where}) - Deletes the first documents that matches where from the collection. it returns the document that has been deleted.

    • model - Mongoose model.
    • where - MongoDB filter object.
  • destroyAll({model: where}) - Deletes all documents that matches where from the collection.

    • model - Mongoose model.
    • where - MongoDB filter object.

Examples

Store

const qc = require('quick-crud')

qc.store({model: UserModel, data: {
	name: 'John',
	username: 'johnDoe'
}}).then((d) => console.log(d))

Example Response

{
  _id: 'xxxx',
  name: 'John',
  username: 'johnDoe',
  __v: 0
}

Index

Fetch all resources with pagination

Fetch all users

const qc = require('quick-crud')

qc.index({model: UserModel}).then((doc) => {
	console.log(doc)
})

Response

{
  currentPage: 1,
  pageCount: 1,
  resourceCount: 4,
  data: [
    {
      _id: 'xxxxxx',
      name: 'User 1',
      username: 'username1',
      __v: 0
    },
    {
      _id: 'xxxxxx',
      name: 'User 2',
      username: 'username2',
      __v: 0
    },
    //..............
  ]
}

Fetch all posts with user polulation

const qc = require('quick-crud')

qc.index({model: PostModel, paginationOptions: {
	page: 2,
	limit: 5
} , populationOptions: {path : 'user'}}).then((doc) => {
	console.log(doc)
})

Response

{
	"currentPage": 2,
	"pageCount": 2,
	"resourceCount": 10,
	"data": [
		{
			"_id": "xxxx",
			"title": "example title 1",
			"body": "example body 1",
			"user": {
				"_id": "xxxx",
				"name": "User 1",
				"username": "username1",
				"__v": 0
			},
			"__v": 0
		},
		{
			"_id": "xxxx",
			"title": "example title 1",
			"body": "example body 1",
			"user": {
				"_id": "xxxx",
				"name": "User 2",
				"username": "username2",
				"__v": 0
			},
			"__v": 0
		}
		// ........................
		// ........................
	]
}

Fetch all posts those are published

qc.index({model: PostModel, where: { published: true }, paginationOptions: {
	page: 2,
	limit: 5
}}).then((doc) => {
	console.log(doc)
})

Response

{
  currentPage: 1,
  pageCount: 1,
  resourceCount: 3,
  data: [
    {
      _id: 'xxxx',
      title: 'post1',
      published: true,
      __v: 0
    },
    {
      _id: 'xxxx',
      title: 'post1',
      published: true,
      __v: 0
    },
    {
      _id: 'xxxx',
      title: 'post1',
      published: true,
      __v: 0
    }
  ]
}

Update

Update a post by id

const qc = require('quick-crud')

qc.update(
{	model: Post,
	where: { _id: 'xxxx' },
  	data: {
		title: 'title updated'
	}}
).then((doc) => console.log(doc))

Response

{
    _id: 'xxxx',
    title: 'title updated',
    body: 'example body 10',
    user: 'xxxx',
    __v: 0
}

Destroy

Delete a user with username

const qc = require('quick-crud')

qc.destroy({model: User, where: {
	username: 'newusername'
}}).then((doc) => {
	console.log(doc)
})

Response

{
  _id: 'xxxx',
  name: 'new name',
  __v: 0,
  username: 'newusername'
}

Throws exception if no document found

// Exception
UnhandledPromiseRejectionWarning: QuickCrudException: Resource not found
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].