sef

sequelize-express-findbyid

Find by id using a sequelize model, returning 404 error if not found

Showing:

Popularity

Downloads/wk

13

GitHub Stars

2

Maintenance

Last Commit

1yr ago

Contributors

1

Package

Dependencies

0

Size (min+gzip)

0.3KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

sequelize-express-findbyid npm npm JavaScript Style Guide npm

Find by id using a sequelize model, returning 404 error if not found

Install

npm i -S sequelize-express-findbyid
or
npm install --save sequelize-express-findbyid

API

const sef = sequelize-express-findbyid (model[, primaryKey = 'id'])

Usage

const sef = require(`sequelize-express-findbyid`)
const findById = sef(Model) // Primary key is 'id'
const findByOtherId = sef(Model, 'OtherId') // Primary key is 'OtherId'

router.get('/:id', (req, res, next) => {
  findById(req.params.id).then(result => res.send(result))
    .catch(e => next(e))
})

Full await/async example inside express router

const express = require('express')
const sef = require(`sequelize-express-findbyid`)

const router = express.Router()
const db = require(`./db`) // Your sequelize models
const Model = db.ModelName // Your model
const findById = sef(Model) // Primary key is 'id'

router.get('/:id', async (req, res, next) => {
  res.send(await findById(req.params.id))
})

License

MIT Copyright © Diego Rodríguez Baquero

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial