trailpack-js-data
Trailpack for js-data ORM
Loads Application Models (in api/models
) into the js-data ORM; Integrates with trailpack-router to
generate Footprints for routes.
This ORM works with sqlite
, mysql
, postgres
, mongodb
and can easily be updated to support even more! Such as redis
and rethink
.
Install
with npm:
$ npm install --save trailpack-js-data
with yo:
$ yo trails:trailpack trailpack-js-data
Configure
// config/main.jsmoduleexports = packs: // ... other trailpacks
A basic config/database.js
can be found here : https://github.com/scott-wyatt/trailpack-js-data/blob/master/archetype/config/database.js
Models
moduleexports = //More about supported schema here : http://www.js-data.io/docs/js-data-schema static { return name: type: 'string' allowNull: false password: 'string' displayName: 'string' } static { return migrate: 'drop' //override default models configurations if needed store: 'sqlite' //override default models configurations if needed //More informations about supported models options here: http://www.js-data.io/docs/relations options: relations: hasOne: profile: localField: 'profile' foreignKey: 'userId' { } }
Query
// api/services/UserService.jsmoduleexports = /** * Finds people with the given email. * @return Promise * @example { * name: 'Ludwig Beethoven', * email: 'someemail@email.com', * favoriteColors: [ * { name: 'yellow', hex: 'ffff00' }, * { name: 'black', hex: '000000' } * ] * } */ { // More info about queries here: http://www.js-data.io/docs/query-syntaxlatest/docs/models-usage/ return thisappormUser } /** * Finds people with the given email with footprints. * @return Promise * @example { * name: 'Ludwig Beethoven', * email: 'someemail@email.com', * favoriteColors: [ * { name: 'yellow', hex: 'ffff00' }, * { name: 'black', hex: '000000' } * ] * } */ { // This ORM can also use footprints! retrun thisappservicesFootprintService }
Footprints query options
Some options can be provide as query param for the find
method, example GET /api/v1/user
.
Populate
You can add /api/v1/user?populate=all
to populate all associations or use /api/v1/user?populate=field1,field2
to populate only some association.
Pagination
By settings offset
and limit
you can do some pagination, example /api/v1/user?offset=10&limit=10
will return only 10 items started from 10 (id 10 to 20).
Contributing
We love contributions! Please check out our Contributor's Guide for more information on how our projects are organized and how to get started.