koa-sequelize-rest
Generates REST middlewares for Sequelize models.
Examples
Simple setup
let koa = ;let Rest = ; let app = ; let Model = ;let ModelRest = Model; app;
Returns
Router example
koa-sequelize-rest is especially handy when used alongside koa-router :
let router = ; router;router;router;router;router; app;app;
API
new Rest(model)
Instanciate a new koa-sequelize-rest helper instance.
Signature
- (param)
model
, a Sequelize model - (returns)
rest
, a Rest instance tied tomodel
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'sinstance.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'sinstance.update
- (returns) a generator
rest.delete()
Deletes an instance of model
.
Signature
- (returns) a generator
License
MIT