zeanium-node
Advanced tools
Comparing version 0.6.22 to 0.6.23
{ | ||
"name": "zeanium-node", | ||
"version": "0.6.22", | ||
"version": "0.6.23", | ||
"description": "Zeanium for Node.js, simple http server and custome your business.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
zn.define([ | ||
'./Model', | ||
'./ModelSql', | ||
'./Collection', | ||
'./Store' | ||
]); |
@@ -19,5 +19,8 @@ /** | ||
this.getProperties(function (prop, key){ | ||
if(prop.hidden){ | ||
return -1; | ||
} | ||
prop.name = key; | ||
var _sql = this.__getPropertyCreateSql(prop); | ||
if(props.primary){ | ||
if(prop.primary){ | ||
_fields.unshift(_sql); | ||
@@ -28,3 +31,3 @@ }else { | ||
return false; | ||
return -1; | ||
}, this); | ||
@@ -37,5 +40,140 @@ | ||
}, | ||
getValues: function (values){ | ||
var _values = {}, | ||
_value = null; | ||
this.getProperties(function (prop, key, props){ | ||
if(prop.ignore){ | ||
return false; | ||
} | ||
_value = values[key]; | ||
if(_value == null){ | ||
_value = prop.get && prop.get.call(this, key, prop, props); | ||
} | ||
switch (prop.type[0].toLowerCase()) { | ||
case 'int': | ||
case 'float': | ||
_value = +_value; | ||
if(isNaN(_value)){ | ||
return -1; | ||
} | ||
break; | ||
case 'datetime': | ||
_value = _value.trim(); | ||
if(!_value){ | ||
return -1; | ||
} | ||
break; | ||
} | ||
if(_value != null) { | ||
_values[key] = _value; | ||
} | ||
}, this); | ||
return _values; | ||
}, | ||
getUpdates: function (updates){ | ||
var _updates = {}, | ||
_value = null; | ||
this.getProperties(function (prop, key, props){ | ||
var _auto_update = prop.auto_update; | ||
if(_auto_update){ | ||
if(typeof _auto_update == 'function'){ | ||
_auto_update = _auto_update.call(this, prop, key, props); | ||
} | ||
if(_auto_update!=null){ | ||
_updates[key] = _auto_update; | ||
} | ||
}else { | ||
if(updates[key]!=null){ | ||
_updates[key] = updates[key]; | ||
} | ||
} | ||
}, this); | ||
return _updates; | ||
}, | ||
getSelectFields: function (inFields, hidden){ | ||
var _props = this.getProperties(), | ||
_hidden = hidden || []; | ||
var fields = inFields||Object.keys(_props); | ||
if(typeof fields == 'function'){ | ||
fields = fields.call(this); | ||
} | ||
if(fields){ | ||
if(typeof fields == 'string'){ | ||
fields = fields.split(','); | ||
} | ||
}else { | ||
fields = Object.keys(_props); | ||
} | ||
var _prop = null, | ||
_fields = [], | ||
_format = null, | ||
_convert = null; | ||
zn.each(fields, function (field, index){ | ||
field = field.trim(); | ||
if((field).toString().indexOf(' as ')!=-1){ | ||
_fields.push(field); | ||
return -1; | ||
} | ||
if(_hidden.indexOf(field)!=-1){ | ||
return -1; | ||
} | ||
if(typeof index == 'string'){ | ||
_fields.push(field + ' as ' + index); | ||
} else { | ||
_prop = _props[field]; | ||
if(!_prop || _prop.hidden){ | ||
return -1; | ||
} | ||
_format = _prop.format; | ||
_convert = _prop.convert; | ||
if(_convert){ | ||
_fields.push(_convert.replace(/\{\}/g, field) + ' as ' + field + '_convert') | ||
} | ||
if(_format){ | ||
_fields.push(_format.replace(/\{\}/g, field) + ' as ' + field); | ||
}else { | ||
_fields.push(field); | ||
} | ||
} | ||
}); | ||
return _fields.join(','); | ||
}, | ||
getInsertSql: function (argv){ | ||
argv.table = this.getMeta('table'); | ||
argv.values = this.getValues(argv.values); | ||
return zn.sql.insert(argv); | ||
}, | ||
getSelectSql: function (argv){ | ||
argv.table = this.getMeta('table'); | ||
if(typeof argv.fields == 'string' && argv.fields.indexOf(' as ')!=-1){ | ||
//console.log(argv.fields); | ||
}else { | ||
argv.fields = this.getSelectFields(argv.fields, argv.hidden); | ||
} | ||
return zn.sql.select(argv); | ||
}, | ||
getDeleteSql: function (argv){ | ||
argv.table = this.getMeta('table'); | ||
return zn.sql.delete(argv); | ||
}, | ||
getUpdateSql: function (argv){ | ||
argv.table = this.getMeta('table'); | ||
argv.updates = this.getUpdates(argv.updates); | ||
return zn.sql.update(argv); | ||
}, | ||
getPagingSql: function (argv){ | ||
argv.table = this.getMeta('table'); | ||
argv.fields = this.getSelectFields(argv.fields); | ||
return zn.sql.paging(argv); | ||
}, | ||
__getPropertyCreateSql: function (property){ | ||
var _key = property.name, | ||
_type = prototype.type || [], | ||
_type = property.type || [], | ||
_t1 = _type[0], | ||
@@ -106,2 +244,3 @@ _t2 = _type[1], | ||
table: { | ||
hidden: true, | ||
get: function (){ | ||
@@ -112,2 +251,3 @@ return this._table; | ||
props: { | ||
hidden: true, | ||
get: function (){ | ||
@@ -114,0 +254,0 @@ return this._props; |
@@ -12,2 +12,10 @@ /** | ||
}, | ||
properties: { | ||
config: { | ||
readonly: true, | ||
get: function (){ | ||
return this._config; | ||
} | ||
} | ||
}, | ||
methods: { | ||
@@ -17,3 +25,4 @@ init: { | ||
value: function (inConfig){ | ||
this._pool = ConnectionPool.getPool(inConfig || {}); | ||
this._config = zn.extend({}, inConfig); | ||
this._pool = ConnectionPool.getPool(this._config); | ||
} | ||
@@ -27,2 +36,5 @@ }, | ||
}, | ||
createDataBase: function () { | ||
return this._pool.createDataBase(this._config.database); | ||
}, | ||
createModel: function (ModelClass) { | ||
@@ -29,0 +41,0 @@ return this._pool.query(ModelClass.getCreateSql()); |
@@ -30,2 +30,3 @@ /** | ||
createDataBase: function (database){ | ||
var _defer = zn.async.defer(); | ||
var _config = zn.extend({}, this._config), | ||
@@ -36,5 +37,14 @@ _database = database || _config.database, | ||
delete _config.database; | ||
require('mysql').createConnection(_config) | ||
.query(_sql, function (err, rows, fields){ | ||
if(err){ | ||
zn.error('mysql.createConnection query error: ', err.stack); | ||
console.log(err.stack); | ||
_defer.reject(err); | ||
}else { | ||
_defer.resolve(rows); | ||
} | ||
}); | ||
return this.__query(_sql, _config); | ||
return _defer.promise; | ||
}, | ||
@@ -41,0 +51,0 @@ query: function (){ |
@@ -22,3 +22,3 @@ zn.define([ | ||
value: function (request, response, chain){ | ||
this.store().setup().then(function (data){ | ||
this.store().createDataBase().then(function (data){ | ||
response.success(data); | ||
@@ -25,0 +25,0 @@ }, function (error){ |
@@ -15,3 +15,2 @@ /** | ||
) { | ||
var _package = require("../../../package.json"); | ||
@@ -18,0 +17,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
256070
6002
124