ee-bookshelf-schema

simple schema definitoion for bookshelf.js

ee-bookshelf-schema

DEPRECATED: we're now using ee-orm instead of this module & bookshelf. This module will not be maintained anymore.

simple schema definitoion for bookshelf.js

npm install 

you may need to install the libpq-dev library

sudo apt-get install libpq-dev

For the detailed usage see the bookshelf & knex docs

if you want to debug the sql generated by bookshelf you can use the command line argument «--debug» or «--debug-db»

!function(){

	var   Class 		= require('ee-class')
		, log 			= require('ee-log')
		, BaseModel 	= require('ee-bookshelf-schema').BaseModel;



	module.exports = new Class({ 
		inherits: BaseModel

		// the name of your table
		, name: 'user'

		// the name of the id on this table if other than «id»
		, idAttribute: 'id'

		// the name of the collection
		, collection: 'users'

		// mapping
		, role: {
			belongsToMany: {
				  table: 	'user_role'
				, key: 		'id_user'
				, otherKey: 'id_role'
			}
		}

		// has many, the string is the fk in the other table
		, session: {
			hasMany: 'id_user'
		}

		// has one, the string is the fk in the other table
		, profile: {
			hasOne: 'id_user'
		}

		// belongs to, the string is the fk in this table
		, organization: {
			belongsTo: 'id_organization'
		}
	});
}();
var Schema = require('ee-bookshelf-schema');


var schema = new Schema({
	  dialect: 	'postgres'
	, host: 	''
	, port: 	
	, user: 	'postgres'
	, password: ''
	, database: 'wpm'
	, models: 	'./schema'
});



schema.on('load', function(){
	new schema.user({id: 11}).fetch().exec(function(err, user){
		log(err, JSON.stringify(user));
	});
});


// colelctions can be found on the colelction object
// schema.collection
  • 0.1.0: initial release
  • 0.1.1: added tests
  • 0.1.2: added correct collection initialization (@huliseerow)
  • 0.1.3: added the getDefinition method to the model
  • 0.1.4: collections have now the same name as the correponsing model if not specified other
  • 0.1.5: added command line arguments «--debug» && «--debug-db»
  • 0.1.6: the «getDefinition» method returns now more userful information
  • 0.1.7: bugfix release
  • 0.1.8: bugfix release
  • 0.1.9: added model property to the definition