diff --git a/lib/classes/Model.js b/lib/classes/Model.js index 50c020f..c691ac5 100644 --- a/lib/classes/Model.js +++ b/lib/classes/Model.js @@ -7,7 +7,7 @@ var injector = require( 'injector' ) , moduleLdr = injector.getInstance( 'moduleLoader' ) , models = {}; -module.exports = Class.extend( +var Model = Class.extend( /* @Static */ { // Either 'ORM' or 'ODM' @@ -23,6 +23,65 @@ module.exports = Class.extend( versionable: false, timeStampable: true, + Types: { + ENUM: function() { + return { + type: this.ENUM, + values: [].slice.call( arguments ), + toString: function() { + return this.type; + } + } + }, + BIGINT: function( length ) { + return { + type: this.BIGINT, + length: length, + toString: function() { + return this.type; + } + } + }, + FLOAT: function( length, decimals ) { + var field = { + type: this.FLOAT, + length: length, + toString: function() { + return this.type; + } + } + + if ( decimals !== undefined ) { + field.decimals = decimals; + } + + return field; + }, + DECIMAL: function( precision, scale ) { + var field = { + type: this.DECIMAL, + precision: precision, + toString: function() { + return this.type; + } + } + + if ( scale !== undefined ) { + field.scale = scale; + } + + return field; + }, + TEXT: function() { + return { + type: this.TEXT, + toString: function() { + return this.type; + } + } + } + }, + // The function you call to create a new model extend: function() { var extendingArgs = [].slice.call( arguments ) @@ -70,11 +129,6 @@ module.exports = Class.extend( Static._driver = driver = injector.getInstance( modelType.toLowerCase() === 'orm' ? 'cleverOrm' : 'cleverOdm' ); } - debug( 'Defining models this.debug() helper...' ); - Proto.debug = Static.debug = function( msg ) { - driver.debug( modelName + 'Model: ' + msg ); - }; - debug( 'Checking for defined getters and setters...' ); if ( Proto.getters !== undefined ) { @@ -90,6 +144,11 @@ module.exports = Class.extend( debug( 'Defining schema...' ); Object.keys( Proto ).forEach( this.callback( 'getSchemaFromProto', Proto, Static ) ); + debug( 'Defining models this.debug() helper...' ); + Proto.debug = Static.debug = function( msg ) { + driver.debug( modelName + 'Model: ' + msg ); + }; + debug( 'Setting up behaviours...' ); [ 'softDeletable', 'versionable', 'timeStampable' ].forEach(function( behaviour ) { @@ -131,7 +190,7 @@ module.exports = Class.extend( getSchemaFromProto: function( Proto, Static, key ) { var prop = Proto[ key ]; - if ( prop === Date || prop === String || prop instanceof String || prop === Number || prop === Boolean || ( typeof prop === 'object' ) ) { + if ( key !== 'defaults' ) { if ( typeof Static._schema !== 'object' ) { Static._schema = {}; } @@ -498,4 +557,26 @@ module.exports = Class.extend( return json; } -}); \ No newline at end of file +}); + +Model.Types.ENUM.toString = function() { + return 'ENUM'; +}; + +Model.Types.BIGINT.toString = function() { + return 'BIGINT'; +}; + +Model.Types.FLOAT.toString = function() { + return 'FLOAT'; +}; + +Model.Types.DECIMAL.toString = function() { + return 'DECIMAL'; +}; + +Model.Types.TEXT.toString = function() { + return 'TEXT'; +}; + +module.exports = Model; \ No newline at end of file diff --git a/package.json b/package.json index df70711..d587a48 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "main": "app.js", "name": "node-seed", "description": "Cleverstack Node-Seed", - "version": "1.0.3", + "version": "1.0.4", "author": { "name": "CleverStack", "email": "admin@cleverstack.io", @@ -56,4 +56,4 @@ "supertest": "" }, "bundledDependencies": [] -} +} \ No newline at end of file