All Projects → lalalilo → express-crud-router

lalalilo / express-crud-router

Licence: other
Simply expose resource CRUD (Create Read Update Delete) routes for Express & Sequelize. Compatible with React Admin Simple Rest Data Provider

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to express-crud-router

Express Sequelize Crud
Simply expose resource CRUD (Create Read Update Delete) routes for Express & Sequelize. Compatible with React Admin Simple Rest Data Provider
Stars: ✭ 65 (-40.37%)
Mutual labels:  crud, expressjs, sequelize, express-js, react-admin
todo-list
A practical web application built with Node.js, Express, and MySQL for you to readily record, view, and manage your tasks with an account: Create, view, edit, delete, filter, and sort expenses are as easy as pie 🥧
Stars: ✭ 18 (-83.49%)
Mutual labels:  crud, expressjs, sequelize
Crudbooster
Laravel CRUD Generator, Make an Advanced Web Application Quickly
Stars: ✭ 1,580 (+1349.54%)
Mutual labels:  crud, crud-generator
React Admin Low Code
react-admin (via ra-data-hasura-graphql provider) + hasura = :)
Stars: ✭ 161 (+47.71%)
Mutual labels:  crud, react-admin
laravel-crud-generator
Generate a CRUD scaffold with validation rules like a breeze.
Stars: ✭ 137 (+25.69%)
Mutual labels:  crud, crud-generator
Mern Stack Authentication
Secure MERN Stack CRUD Web Application using Passport.js Authentication
Stars: ✭ 60 (-44.95%)
Mutual labels:  crud, expressjs
Mean Stack Angular6 Crud Example
MEAN Stack Angular 6 CRUD Web Application
Stars: ✭ 69 (-36.7%)
Mutual labels:  crud, expressjs
1702-express-review
Review repo for express.js and sequelize for Fullstack Academy/Grace Hopper Academy 1702 cohort
Stars: ✭ 35 (-67.89%)
Mutual labels:  sequelize, express-js
Dancer-Plugin-SimpleCRUD
Quick and effortless CRUD (create/read/update/delete) operations based on database tables
Stars: ✭ 25 (-77.06%)
Mutual labels:  crud, crud-generator
lara-crud
This package will give an opportunity to get a very flexible admin panel that will satisfy you most of the time.
Stars: ✭ 33 (-69.72%)
Mutual labels:  crud, crud-generator
node-express-mongodb-reactjs-graphql
Node, Express, React.js, Graphql and MongoDB CRUD Web Application
Stars: ✭ 36 (-66.97%)
Mutual labels:  crud, expressjs
crudcast
Create and deploy a RESTful API with a few lines of YAML
Stars: ✭ 32 (-70.64%)
Mutual labels:  crud, crud-generator
Nestjs Query
Easy CRUD for GraphQL.
Stars: ✭ 325 (+198.17%)
Mutual labels:  crud, sequelize
Mean Stack Angular5 Crud
MEAN Stack (Angular 5) CRUD Web Application Example
Stars: ✭ 107 (-1.83%)
Mutual labels:  crud, expressjs
Crud
CRUD PORTO Containers for apiato and Angular2 modules generator, based on Laravel 5.4 and Angular 2.4+
Stars: ✭ 23 (-78.9%)
Mutual labels:  crud, crud-generator
Crud
NestJs CRUD for RESTful APIs
Stars: ✭ 2,709 (+2385.32%)
Mutual labels:  crud, crud-generator
auto-async-wrap
automatic async middleware wrapper for expressjs errorhandler.
Stars: ✭ 21 (-80.73%)
Mutual labels:  expressjs, express-js
NodeExpressCRUD
Node, Express, Mongoose and MongoDB CRUD Web Application
Stars: ✭ 45 (-58.72%)
Mutual labels:  crud, expressjs
ncg-crud-ngx-md
Angular 4+ Material Design CRUD/Admin app by NinjaCodeGen http://DNAfor.NET
Stars: ✭ 36 (-66.97%)
Mutual labels:  crud, crud-generator
express-file-upload
Node.js Express Upload/Download File Rest APIs example with Multer
Stars: ✭ 64 (-41.28%)
Mutual labels:  expressjs, express-js

express-crud-router

codecov CircleCI

Expose resource CRUD (Create Read Update Delete) routes in your Express app. Compatible with React Admin Simple Rest Data Provider. The lib is ORM agnostic. List of existing ORM connectors.

import crud from 'express-crud-router'

app.use(
  crud('/admin/users', {
    getList: ({ filter, limit, offset, order }) =>
      User.findAndCountAll({ limit, offset, order, where: filter }),
    getOne: id => User.findByPk(id),
    create: body => User.create(body),
    update: (id, body) => User.update(body, { where: { id } }),
    destroy: id => User.destroy({ where: { id } }),
  })
)

Note: Content-Range header

For getList methods, the response includes the total number of items in the collection in X-Total-Count header. You should use this response header for pagination and avoid using Content-Range header if your request does not include a Range header. Checkout this stackoverflow thread for more info.

If you are using ra-data-simple-rest, please refer to the documentation to use X-Total-Count for pagination.

Install

npm install express-crud-router

Usage

Simple use case

import express from 'express'
import crud from 'express-crud-router'
import sequelizeCrud from 'express-crud-router-sequelize-v6-connector'
import { User } from './models'

const app = new express()
app.use(crud('/admin/users', sequelizeCrud(User)))

Limit actions

import express from 'express'
import crud from 'express-crud-router'
import sequelizeCrud from 'express-crud-router-sequelize-v6-connector'
import { User } from './models'

const app = new express()
app.use(
  crud('/admin/users', {
    ...sequelizeCrud(User),
    destroy: null,
  })
)

Custom filters

Custom filters such as case insensitive filter can be perform like this:

import express from 'express'
import { Op } from 'sequelize'
import crud from 'express-crud-router'
import sequelizeCrud from 'express-crud-router-sequelize-v6-connector'
import { User } from './models'

const app = new express()
app.use(
  crud('/admin/users', sequelizeCrud(User), {
    filters: {
      email: value => ({
        [Op.iLike]: value,
      }),
    },
  })
)

Custom behavior & other ORMs

import express from 'express'
import crud from 'express-crud-router'
import { User } from './models'

const app = new express()
app.use(
  crud('/admin/users', {
    getList: ({ filter, limit, offset, order, opts: { req, res } }) =>
      User.findAndCountAll({ limit, offset, order, where: filter }),
    getOne: (id, { req, res }) => User.findByPk(id),
    create: (body, { req, res }) => User.create(body),
    update: (id, body, { req, res }) => User.update(body, { where: { id } }),
    destroy: (id, { req, res }) => User.destroy({ where: { id } }),
  })
)

An ORM connector is a lib exposing an object of following shape:

interface Actions<R> {
  getOne: (identifier: string) => Promise<R | null>
  create: (body: R) => Promise<R & { id: number | string }>
  destroy: (id: string) => Promise<any>
  update: (id: string, data: R) => Promise<any>
  getList: GetList<R> = (conf: {
    filter: Record<string, any>
    limit: number
    offset: number
    order: Array<[string, string]>
  }) => Promise<{ rows: R[]; count: number }>
}

Search

Autocomplete

When using react-admin autocomplete reference field, a request is done to the API with a q filter. Thus, when using the autocomplete field in react-admin, you must specify the behavior to search the records. This could looks like:

app.use(
  crud('/admin/users', {
    search: async (q, limit) => {
      const { rows, count } = await User.findAndCountAll({
        limit,
        where: {
          [Op.or]: [
            { address: { [Op.iLike]: `${q}%` } },
            { zipCode: { [Op.iLike]: `${q}%` } },
            { city: { [Op.iLike]: `${q}%` } },
          ],
        },
      })

      return { rows, count }
    },
  })
)

express-crud-router ORM connectors might expose some search behaviors.

Contribute

This lib uses semantic-release. You need to write your commits following this nomenclature:

  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, - formatting, missing semi-colons, etc)
  • refactor: A code change that neither fixes a bug nor adds a feature
  • perf: A code change that improves performance
  • test: Adding missing or correcting existing tests
  • chore: Changes to the build process or auxiliary tools and libraries such as documentation generation

To trigger a major version release write in the core of the commit message:

feat: my commit

BREAKING CHANGE: detail here
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].