From bbf9da3ec948ae88f86903716ef0ef873d2e5492 Mon Sep 17 00:00:00 2001 From: Richard Gustin Date: Sun, 15 Jun 2014 03:36:02 +1000 Subject: [PATCH 1/3] feat(models): Code needed to support expanded model data types --- lib/classes/Model.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/classes/Model.js b/lib/classes/Model.js index 50c020f..76f4f59 100644 --- a/lib/classes/Model.js +++ b/lib/classes/Model.js @@ -23,6 +23,18 @@ module.exports = Class.extend( versionable: false, timeStampable: true, + Types: { + ENUM: function() { + return { + type: this.ENUM, + values: [].slice.call( arguments ), + toString: function() { + return this.type; + } + } + } + }, + // The function you call to create a new model extend: function() { var extendingArgs = [].slice.call( arguments ) From 469398b2ffdd6e0b9ca70fee16cd01b4abf22314 Mon Sep 17 00:00:00 2001 From: Richard Gustin Date: Sun, 15 Jun 2014 04:55:30 +1000 Subject: [PATCH 2/3] feat(models): Allow all possible fields to be defined in _schema --- lib/classes/Model.js | 85 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 8 deletions(-) diff --git a/lib/classes/Model.js b/lib/classes/Model.js index 76f4f59..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' @@ -32,6 +32,53 @@ module.exports = Class.extend( 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; + } + } } }, @@ -82,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 ) { @@ -102,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 ) { @@ -143,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 = {}; } @@ -510,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 From 39743a15a782fc3f4d66626c5bd9545c5a31b158 Mon Sep 17 00:00:00 2001 From: Richard Gustin Date: Sun, 15 Jun 2014 12:08:02 +1000 Subject: [PATCH 3/3] release(1.0.4): Updated model support --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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