Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    ee-bookshelf-schemapublic

    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

    installation

    npm install 
    

    you may need to install the libpq-dev library

    sudo apt-get install libpq-dev
    

    usage

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

    Schema

    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
    

    CHANGELOG

    • 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

    Keywords

    none

    install

    npm i ee-bookshelf-schema

    Downloadsweekly downloads

    19

    version

    0.1.10

    license

    none

    repository

    githubgithub

    last publish

    collaborators

    • avatar