Socket
Socket
Sign inDemoInstall

koa-sequelize-rest

Package Overview
Dependencies
4
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    koa-sequelize-rest

Sequelize Rest Middlewares for Koa


Version published
Weekly downloads
11
increased by1000%
Maintainers
1
Install size
1.46 MB
Created
Weekly downloads
 

Readme

Source

koa-sequelize-rest

Generates REST middlewares for Sequelize models.

Examples

Simple setup

let koa = require('koa');
let Rest = require('koa-sequelize-rest');

let app = koa();

let Model = require('./model');
let ModelRest = new Rest(Model);

app.use(ModelRest.readAll());

Returns

{
  "model": [
    { "value": "A" },
    { "value": "B" },
    { "value": "C" }
  ]
}

Router example

koa-sequelize-rest is especially handy when used alongside koa-router :

let router = koaRouter();

router.get('/', ModelRest.readAll());
router.post('/', ModelRest.create());
router.get('/:uuid', ModelRest.readOne());
router.put('/:uuid', ModelRest.update());
router.delete('/:uuid', ModelRest.delete());

app.use(router.routes());
app.use(router.allowedMethods());

API

new Rest(model)

Instanciate a new koa-sequelize-rest helper instance.

Signature
  • (param) model, a Sequelize model
  • (returns) rest, a Rest instance tied to model

rest.getEntity(includes)

Loads a model instance in Koa's context state.

Signature
  • (param) includes
  • (returns) a generator

rest.readOne()

Fetches a model instance and returns it in the response.

Signature
  • (returns) a generator

rest.readAll(options)

Fetches a bunch of model instances and returns them in the response.

Signature
  • (param) options, a javascript object passed on to Sequelize's instance.findAll
  • (returns) a generator

rest.create()

Creates and saves a new instance of model, then returns the newly created instance in the response.

Signature
  • (returns) a generator

rest.update(options)

Updates an instance of model, then returns the updated instance in the response.

Signature
  • (param) options, a javascript object passed on to Sequelize's instance.update
  • (returns) a generator

rest.delete()

Deletes an instance of model.

Signature
  • (returns) a generator

License

MIT

Keywords

FAQs

Last updated on 30 Mar 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc