cah-base-model

1.0.0 • Public • Published

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')
  }));
}

Readme

Keywords

none

Package Sidebar

Install

npm i cah-base-model

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • bjy