clever-orm
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -8,3 +8,3 @@ var injector = require( 'injector' ) | ||
, fs = require( 'fs' ) | ||
, ormUtils = require( path.resolve( path.join( __dirname, '..', 'lib', 'utils.js' ) ) ) | ||
, ormUtils = utils.ormUtils | ||
, env = utils.bootstrapEnv() | ||
@@ -11,0 +11,0 @@ , moduleLdr = env.moduleLoader; |
@@ -1,5 +0,4 @@ | ||
var path = require( 'path' ) | ||
, ormUtils = require( path.resolve( path.join( __dirname, '..', 'lib', 'utils.js' ) ) ) | ||
var utils = require( 'utils' ) | ||
, ormUtils = utils.ormUtils | ||
, async = require( 'async' ) | ||
, utils = require( 'utils' ) | ||
, env = utils.bootstrapEnv() | ||
@@ -6,0 +5,0 @@ , moduleLdr = env.moduleLoader |
@@ -72,3 +72,3 @@ var injector = require( 'injector' ) | ||
models[ association.source.name ]._setters[ association.identifier ] = function( val ) { | ||
this._model[ association.identifier ] = val; | ||
this._model[ association.as ] = val; | ||
}; | ||
@@ -231,4 +231,5 @@ | ||
parseSchemaField: function( Static, fields, name ) { | ||
var options = Static._schema[ name ] | ||
, fieldDefinition = {}; | ||
var fieldDefinition = {} | ||
, columnName = name | ||
, options = Static._schema[ name ] | ||
@@ -249,4 +250,12 @@ // Allow direct syntax | ||
// Get the type | ||
fieldDefinition.type = this.getFieldType( Static, options ); | ||
fieldDefinition.type = this.getFieldType( Static, options, name ); | ||
if ( options.columnName ) { | ||
columnName = options.columnName; | ||
options.field = columnName; | ||
} else if ( !!Static.underscored && i.underscore( name ).split( '_' ).length > 1 ) { | ||
columnName = i.underscore( name ); | ||
options.field = columnName; | ||
} | ||
// Handle options | ||
@@ -256,3 +265,3 @@ [ 'allowNull', 'primaryKey', 'autoIncrement', 'unique', 'default', 'comment' ].forEach(function( optionName ) { | ||
if ( optionName === 'primaryKey' ) { | ||
Static.primaryKey = name; | ||
Static.primaryKey.push( name ); | ||
} | ||
@@ -264,9 +273,9 @@ | ||
fields[ name ] = fieldDefinition; | ||
fields[ columnName ] = fieldDefinition; | ||
}, | ||
getFieldType: function( Static, options ) { | ||
getFieldType: function( Static, options, name ) { | ||
var field; | ||
switch( options.type ) { | ||
switch( options.type.type || options.type ) { | ||
@@ -277,3 +286,7 @@ case Number: | ||
case String: | ||
field = Sequelize.STRING; | ||
if ( options.length ) { | ||
field = Sequelize.STRING( options.length ); | ||
} else { | ||
field = Sequelize.STRING; | ||
} | ||
break; | ||
@@ -295,2 +308,5 @@ case Boolean: | ||
break; | ||
case Model.Types.TINYINT: | ||
field = this.tinyIntType( options ); | ||
break; | ||
case Model.Types.BIGINT: | ||
@@ -309,5 +325,5 @@ field = this.bigIntType( options ); | ||
case undefined: | ||
throw new Error( [ 'You must define the type of field that', '"' + name + '"', 'is on the', '"' + Static.name + '" model' ].join( ' ' ) ); | ||
throw new Error( [ 'You must define the type of field that', '"' + name + '"', 'is on the', '"' + Static._name + '" model' ].join( ' ' ) ); | ||
default: | ||
throw new Error( [ 'You must define a valid type for the field named', '"' + name + '"', 'on the', '"' + Static.name + '" model' ].join( ' ' ) ); | ||
throw new Error( [ 'You must define a valid type for the field named', '"' + name + '"', 'on the', '"' + Static._name + '" model' ].join( ' ' ) ); | ||
} | ||
@@ -330,10 +346,22 @@ | ||
tinyIntType: function( options ) { | ||
var field = !!options.length ? 'TINYINT(' + options.length + ')' : 'TINYINT'; | ||
if ( !!options.unsigned && !!options.zerofill ) { | ||
field += ' UNSIGNED ZEROFILL'; | ||
} else if ( !!options.unsigned && !options.zerofill ) { | ||
field += ' UNSIGNED'; | ||
} else if ( !options.unsigned && !!options.zerofill ) { | ||
field += ' ZEROFILL'; | ||
} | ||
return field; | ||
}, | ||
bigIntType: function( options ) { | ||
var field = !!options.length ? Sequelize.BIGINT( options.length ) : Sequelize.BIGINT; | ||
if ( !!options.unsigned && !!options.zerofill ) { | ||
field = bigint.UNSIGNED.ZEROFILL; | ||
field = field.UNSIGNED.ZEROFILL; | ||
} else if ( !!options.unsigned && !options.zerofill ) { | ||
field = bigint.UNSIGNED; | ||
field = field.UNSIGNED; | ||
} else if ( !options.unsigned && !!options.zerofill ) { | ||
field = bigint.ZEROFILL; | ||
field = field.ZEROFILL; | ||
} | ||
@@ -370,2 +398,2 @@ return field; | ||
} | ||
}); | ||
}); |
{ | ||
"name": "clever-orm", | ||
"description": "CleverStack ORM (SQL) Module", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"main": "module.js", | ||
@@ -36,3 +36,3 @@ "author": { | ||
"mysql": "2.0.0-rc2", | ||
"sequelize": "~2.0.0-rc1" | ||
"sequelize": "~2.0.0-rc8" | ||
}, | ||
@@ -39,0 +39,0 @@ "devDependencies": { |
@@ -105,7 +105,7 @@ var utils = require( 'utils' ) | ||
injector.getInstance( 'sequelize' ).query( 'describe Orms;', { raw: true }) | ||
.success(function( desc ) { | ||
.then(function( desc ) { | ||
expect( JSON.stringify( desc ) ).to.equal( '{"id":{"type":"INT(11)","allowNull":false,"defaultValue":null},"str":{"type":"VARCHAR(255)","allowNull":true,"defaultValue":null},"bool":{"type":"TINYINT(1)","allowNull":true,"defaultValue":null},"date":{"type":"DATETIME","allowNull":true,"defaultValue":null},"enum":{"type":"ENUM(\'TEST\')","allowNull":true,"defaultValue":null},"enumObj":{"type":"ENUM(\'TEST\')","allowNull":true,"defaultValue":null},"buf":{"type":"VARCHAR(255)","allowNull":true,"defaultValue":null},"bigint":{"type":"BIGINT(20)","allowNull":true,"defaultValue":null},"bigintLen":{"type":"BIGINT(11)","allowNull":true,"defaultValue":null},"float":{"type":"FLOAT","allowNull":true,"defaultValue":null},"floatLen":{"type":"FLOAT","allowNull":true,"defaultValue":null},"floatLenAndDec":{"type":"FLOAT(11,10)","allowNull":true,"defaultValue":null},"dec":{"type":"DECIMAL(10,0)","allowNull":true,"defaultValue":null},"decPrec":{"type":"DECIMAL(11,0)","allowNull":true,"defaultValue":null},"decPrecAndScale":{"type":"DECIMAL(10,2)","allowNull":true,"defaultValue":null},"text":{"type":"TEXT","allowNull":true,"defaultValue":null},"textObj":{"type":"TEXT","allowNull":true,"defaultValue":null},"createdAt":{"type":"DATETIME","allowNull":true,"defaultValue":null},"updatedAt":{"type":"DATETIME","allowNull":true,"defaultValue":null},"deletedAt":{"type":"DATETIME","allowNull":true,"defaultValue":null}}' ); | ||
done(); | ||
}) | ||
.error( done ) | ||
.catch( done ) | ||
}); | ||
@@ -112,0 +112,0 @@ }); |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
59697
1086
12
Updatedsequelize@~2.0.0-rc8