admit-one-bookshelf
v0.3.0
Published
Admit One adapter for Bookshelf.js
Downloads
2
Maintainers
Readme
Admit One Bookshelf
Admit One adapter for Bookshelf.js.
Install
npm install admit-one admit-one-bookshelf
Usage
var User, Token;
User = bookshelf.Model.extend({
tokens: function() {
return this.hasMany(Token);
},
tableName: 'users'
});
Token = bookshelf.Model.extend({
user: function() {
return this.belongsTo(User);
},
tableName: 'tokens'
});
var admit = require('admit-one')('bookshelf', {
bookshelf: { modelClass: User }
});
Once you have created an instance, see the main Admit One page for details on how to set up your routes with Express.
Migration
For quick reference, a basic migration to create a users table would look like this:
exports.up = function(knex, Promise) {
return knex.schema.createTable('users', function(table) {
table.increments('id').primary();
table.string('username').notNullable();
table.string('passwordDigest').notNullable();
}).createTable('tokens', function(table) {
table.increments('id').primary();
table.integer('user_id').references('users.id');
table.string('value').notNullable();
});
};
exports.down = function(knex, Promise) {
return knex.schema.dropTable('tokens').dropTable('users');
};
API
admit([options])
options.bookshelf.modelClass
Type: Bookshelf.Model
Default: undefined
License
This project is distributed under the MIT license.