1.0.0 • Published 9 years ago

cah-base-model v1.0.0

Weekly downloads
7
License
MIT
Repository
github
Last release
9 years ago

cah-base-model

Intended Usage

Main application

'use strict';

// Set up knex and your bookshelf instance
var knex = require('knex');
var Bookshelf = require('bookshelf');
var db = knex({ client : 'pg', connection : 'postgres://127.0.0.1' });
Bookshelf.Instance = Bookshelf.initialize(db);
Bookshelf.Instance.plugin('registry');

require('cah-base-model')(Bookshelf.Instance);

require('my-user-module')(Bookshelf.Instance); // See below for definition

my-user-module.js

'use strict';

module.exports = function(bookshelf, inheritsFrom) {
  inheritsFrom = inheritsFrom || 'Base';

  bookshelf.model('User', bookshelf.model(inheritsFrom).extend({
    tableName : 'users',
    initialize : function() { console.log('Created a user model'); }
  }));

  bookshelf.collection('User', bookshelf.collection(inheritsFrom).extend({
    model : bookshelf.model('User')
  }));
}
1.0.0

9 years ago