zeanium-node
Advanced tools
Comparing version 0.5.9 to 0.6.0
{ | ||
"name": "zeanium-node", | ||
"version": "0.5.9", | ||
"version": "0.6.0", | ||
"description": "Zeanium for Node.js, simple http server and custome your business.", | ||
@@ -36,3 +36,3 @@ "main": "index.js", | ||
"mysql": "^2.13.0", | ||
"zeanium": "^1.1.15" | ||
"zeanium": "^1.1.16" | ||
}, | ||
@@ -39,0 +39,0 @@ "preferGlobal": "true", |
@@ -116,12 +116,14 @@ # zeanium-node | ||
value: function (request, response, chain){ | ||
this._action.selectOne(request.getValue()).then(function (user){ | ||
if(user){ | ||
request.session.user = user; | ||
response.success(user); | ||
} else { | ||
response.error('Username or password is incorrect.'); | ||
} | ||
}, function (error){ | ||
response.error(error.message); | ||
}); | ||
this.collection('zn_rights_user') | ||
.selectOne(request.getValue()) | ||
.then(function (user){ | ||
if(user){ | ||
request.session.user = user; | ||
response.success(user); | ||
} else { | ||
response.error('Username or password is incorrect.'); | ||
} | ||
}, function (error){ | ||
response.error(error.message); | ||
}); | ||
} | ||
@@ -134,17 +136,2 @@ } | ||
```js | ||
//define user Action | ||
zn.define(function () { | ||
return zn.Action({ | ||
methods: { | ||
getLoginInfo: function (userId){ | ||
} | ||
} | ||
}); | ||
}); | ||
``` | ||
## Try it | ||
@@ -151,0 +138,0 @@ |
@@ -98,6 +98,2 @@ # Zeanium-Node | ||
methods: { | ||
init: function (args){ | ||
//init | ||
this._action = this.action('zn_rights_user'); | ||
}, | ||
//define login action | ||
@@ -111,12 +107,14 @@ login: { | ||
value: function (request, response, chain){ | ||
this._action.selectOne(request.getValue()).then(function (user){ | ||
if(user){ | ||
request.session.user = user; | ||
response.success(user); | ||
} else { | ||
response.error('Username or password is incorrect.'); | ||
} | ||
}, function (error){ | ||
response.error(error.message); | ||
}); | ||
this.collection('zn_rights_user') | ||
.selectOne(request.getValue()) | ||
.then(function (user){ | ||
if(user){ | ||
request.session.user = user; | ||
response.success(user); | ||
} else { | ||
response.error('Username or password is incorrect.'); | ||
} | ||
}, function (error){ | ||
response.error(error.message); | ||
}); | ||
} | ||
@@ -129,17 +127,2 @@ } | ||
```js | ||
//define user Action | ||
zn.define(function () { | ||
return zn.Action({ | ||
methods: { | ||
getLoginInfo: function (userId){ | ||
} | ||
} | ||
}); | ||
}); | ||
``` | ||
## Try it | ||
@@ -146,0 +129,0 @@ |
@@ -6,5 +6,4 @@ /** | ||
'node:fs', | ||
'node:path', | ||
'io' | ||
], function (fs, path, io) { | ||
'node:path' | ||
], function (fs, path) { | ||
@@ -30,6 +29,3 @@ return zn.Class({ | ||
} | ||
zn.info('Creating ' + _type + ': ' + _name + '.'); | ||
io.FileUtil.copyDir(path.normalize(_target), path.normalize(_source), function (){ | ||
zn.info('Creating end.'); | ||
}); | ||
} | ||
@@ -36,0 +32,0 @@ } |
@@ -6,5 +6,4 @@ /** | ||
'node:fs', | ||
'node:path', | ||
'io' | ||
], function (fs, path, io) { | ||
'node:path' | ||
], function (fs, path) { | ||
@@ -11,0 +10,0 @@ return zn.Class({ |
@@ -6,5 +6,4 @@ /** | ||
'node:fs', | ||
'node:path', | ||
'io' | ||
], function (fs, path, io) { | ||
'node:path' | ||
], function (fs, path) { | ||
@@ -33,5 +32,2 @@ return zn.Class({ | ||
fs.mkdirSync(_pluginsDir); | ||
io.FileUtil.copyDir(path.normalize(_target), path.normalize(process.cwd() + zn.SLASH + 'plugins' + zn.SLASH + _name), function (){ | ||
zn.info('Creating end.'); | ||
}); | ||
} else { | ||
@@ -38,0 +34,0 @@ zn.error('The current directory is not an zn app, the file “zn.app.config.js” is required.'); |
@@ -6,5 +6,5 @@ zn.define([ | ||
return { | ||
Tree: Tree | ||
tree: Tree | ||
} | ||
}); |
@@ -10,15 +10,19 @@ /** | ||
addTreeNode: function (table, model){ | ||
var _model = model||{}, | ||
_table = table; | ||
var _fields = [], | ||
_values = []; | ||
for(var key in _model){ | ||
_fields.push(key); | ||
_values.push(_model[key]); | ||
} | ||
var _pid = model.pid || 0; | ||
return zn.createTransactionBlock() | ||
.query('select {0} from {1} where id={2};select max(treeOrder)+1 as treeOrder from {1} where delFlag=0 and pid={2};'.format('id,depth,parentPath,treeOrder', _table, _model.pid||0)) | ||
.query('insert into {0} ({1}) values ({2});update {0} set {3} where id={4};', function (sql, rows, fields){ | ||
.query(zn.sql.select({ | ||
table: table, | ||
fields: 'id,depth,parentPath,treeOrder', | ||
where: { | ||
id: _pid | ||
} | ||
}, { | ||
table: table, | ||
fields: 'max(treeOrder)+1 as treeOrder', | ||
where: { | ||
delFlag: 0, | ||
pid: _pid | ||
} | ||
})) | ||
.query('Insert node && Update parent node', function (sql, rows, fields){ | ||
var _pidModel = rows[0][0], | ||
@@ -30,41 +34,36 @@ _treeOrder = rows[1][0].treeOrder|| 1, | ||
_fields = _fields.concat(['parentPath', 'treeOrder', 'depth']).join(','); | ||
_values = _values.concat([_parentPath, _treeOrder, _depth]); | ||
model.parentPath = _parentPath; | ||
model.treeOrder = _treeOrder; | ||
model.depth = _depth; | ||
_values.forEach(function (value, index){ | ||
if(zn.is(value, 'string')){ | ||
if(value.indexOf('{') === 0 && value.indexOf('}') === (value.length-1)){ | ||
_values[index] = value.substring(1, value.length-1); | ||
}else { | ||
_values[index] = "'" + value + "'"; | ||
} | ||
return zn.sql.insert({ | ||
table: table, | ||
values: model | ||
}) + zn.sql.update({ | ||
table: table, | ||
updates: 'sons=sons+1', | ||
where: { | ||
id: _pid | ||
} | ||
}); | ||
_values = _values.join(','); | ||
return sql.format(_table, _fields, _values, 'sons=sons+1', _pid); | ||
}); | ||
}, | ||
deleteTreeNode: function (table, where){ | ||
var _where = where||{}, | ||
_table = table; | ||
if(zn.is(_where, 'number')){ | ||
_where = { id: _where }; | ||
} | ||
return zn.createTransactionBlock() | ||
.query(zn.sql.select('id,pid,treeOrder').from(_table).where(_where).build()) | ||
.query(zn.sql.select({ | ||
table: table, | ||
fields: 'id, pid, treeOrder', | ||
where: where | ||
})) | ||
.query('delete', function (sql, rows, fields, tran){ | ||
var _model = rows[0]; | ||
if(_model){ | ||
var _sql = 'delete from {0} where id={1};'.format(_table, _model.id), | ||
var _sql = 'delete from {0} where id={1};'.format(table, _model.id), | ||
_pid = +_model.pid; | ||
if(_pid){ | ||
_sql += 'update {0} set sons=sons-1 where id={1};'.format(_table, _pid); | ||
_sql += 'update {0} set sons=sons-1 where id={1};'.format(table, _pid); | ||
} | ||
_sql += 'update {0} set treeOrder=treeOrder-1 where treeOrder>{1} and pid={2};'.format(_table, _model.treeOrder, _pid); | ||
_sql += "delete from {0} where locate(',{1},',parentPath)<>0;".format(_table, _model.id); | ||
_sql += 'update {0} set treeOrder=treeOrder-1 where treeOrder>{1} and pid={2};'.format(table, _model.treeOrder, _pid); | ||
_sql += "delete from {0} where locate(',{1},',parentPath)<>0;".format(table, _model.id); | ||
return _sql; | ||
@@ -76,7 +75,5 @@ } else { | ||
}, | ||
orderTreeNode: function (store, table, id, order){ | ||
var _table = table; | ||
orderTreeNode: function (table, id, order){ | ||
return zn.createTransactionBlock() | ||
.query('select {0} from {1} where id={2};select count(id) as count from {1} where pid=(select pid from {1} where id={2});'.format('id,pid,treeOrder', _table, id)) | ||
.query('select {0} from {1} where id={2};select count(id) as count from {1} where pid=(select pid from {1} where id={2});'.format('id,pid,treeOrder', table, id)) | ||
.query('order', function (sql, rows, fields){ | ||
@@ -102,4 +99,4 @@ var _model = rows[0][0], | ||
var _sql = 'update {0} set treeOrder={1} where treeOrder={2} and pid={3};'.format(_table, _treeOrder, _newOrder, _model.pid); | ||
_sql += 'update {0} set treeOrder={1} where id={2};'.format(_table, _newOrder, _model.id); | ||
var _sql = 'update {0} set treeOrder={1} where treeOrder={2} and pid={3};'.format(table, _treeOrder, _newOrder, _model.pid); | ||
_sql += 'update {0} set treeOrder={1} where id={2};'.format(table, _newOrder, _model.id); | ||
return _sql; | ||
@@ -106,0 +103,0 @@ } else { |
zn.define([ | ||
'./block/', | ||
'./service/', | ||
'./action/', | ||
'./model/' | ||
], function (block, service, action, model) { | ||
], function (block, model) { | ||
zn.block = block; | ||
zn.service = service; | ||
return { | ||
block: block, | ||
service: service, | ||
action: action, | ||
model: model | ||
@@ -15,0 +10,0 @@ } |
@@ -1,5 +0,6 @@ | ||
zn.define('../action/Base', function (BaseAction) { | ||
zn.define(function () { | ||
return zn.Class("zn.db.common.model.Base", zn.db.data.Model, { | ||
action: BaseAction, | ||
properties: { | ||
@@ -16,3 +17,6 @@ id: { | ||
type: ['char', 36], | ||
default: '{uuid()}' | ||
get: function (){ | ||
return '{uuid()}'; | ||
}, | ||
default: '' | ||
},*/ | ||
@@ -22,12 +26,3 @@ title: { | ||
type: ['varchar', 100], | ||
default: '', | ||
common: { | ||
title: '标题' | ||
}, | ||
header: { | ||
width: 150 | ||
}, | ||
input: { | ||
type: 'text' | ||
} | ||
default: '' | ||
}, | ||
@@ -38,8 +33,4 @@ createTime: { | ||
ignore: true, | ||
//format: "date_format({},'%Y-%c-%d %h:%i:%s')", | ||
default: 'now()', | ||
header: { | ||
title: '创建时间', | ||
width: 150 | ||
} | ||
format: "date_format({},'%Y-%c-%d %h:%i:%s')", | ||
default: '{now()}' | ||
}, | ||
@@ -50,14 +41,6 @@ createPerson: { | ||
convert: 'zn_convert_user({})', | ||
//ignore: true, | ||
default: function (){ | ||
if(zn._request.session.hasItem()){ | ||
if(zn._request.session.getItem('@AdminUser')){ | ||
return zn._request.session.getItem('@AdminUser').id; | ||
}else { | ||
return 0; | ||
} | ||
}else { | ||
return 0; | ||
} | ||
} | ||
get: function (){ | ||
return zn._request.getSessionKeyValue('@AdminUser', 'id'); | ||
}, | ||
default: 0 | ||
}, | ||
@@ -68,4 +51,4 @@ modifyTime: { | ||
ignore: true, | ||
auto_update: 'now()', | ||
//format: "date_format({},'%Y-%c-%d %h:%i:%s')", | ||
auto_update: '{now()}', | ||
format: "date_format({},'%Y-%c-%d %h:%i:%s')", | ||
default: null | ||
@@ -78,11 +61,6 @@ }, | ||
ignore: true, | ||
default: function (){ | ||
if(zn._request.session.hasItem()){ | ||
if(zn._request.session.getItem('@AdminUser')){ | ||
return zn._request.session.getItem('@AdminUser').id; | ||
} | ||
}else { | ||
return 0; | ||
} | ||
} | ||
auto_update: function (){ | ||
return zn._request.getSessionKeyValue('@AdminUser', 'id'); | ||
}, | ||
default: 0 | ||
}, | ||
@@ -93,3 +71,3 @@ delFlag: { | ||
ignore: true, | ||
default: '0' | ||
default: 0 | ||
}, | ||
@@ -96,0 +74,0 @@ note: { |
@@ -1,5 +0,5 @@ | ||
zn.define('../action/Rights',function (RightsAction) { | ||
zn.define('../collection/Rights',function (Rights) { | ||
return zn.Class("zn.db.common.model.Rights", zn.db.data.Model, { | ||
action: RightsAction, | ||
collection: Rights, | ||
properties: { | ||
@@ -6,0 +6,0 @@ ownerId: { |
@@ -1,5 +0,5 @@ | ||
zn.define('../action/Tree',function (TreeAction) { | ||
zn.define('../collection/Tree',function (Tree) { | ||
return zn.Class("zn.db.common.model.Tree", zn.db.data.Model, { | ||
action: TreeAction, | ||
collection: Tree, | ||
properties: { | ||
@@ -6,0 +6,0 @@ type: { |
@@ -6,47 +6,62 @@ /** | ||
var SQLS = { | ||
desc: 'desc {table};', | ||
drop: 'drop table {table};', | ||
show: 'show tables;', | ||
addField: 'alter table {table} add {field};', | ||
modifyField: 'alter table {table} modify {field};', | ||
dropField: 'alter table {table} drop {field};', | ||
}; | ||
var Collection = zn.Class('zn.db.data.Collection', { | ||
properties: { | ||
store: { | ||
readonly: true, | ||
get: function (){ | ||
return this._store; | ||
} | ||
}, | ||
Model: { | ||
readonly: true, | ||
get: function (){ | ||
return this._Model; | ||
} | ||
} | ||
}, | ||
methods: { | ||
init: { | ||
auto: true, | ||
value: function (store, ModelClass){ | ||
value: function (store, Model){ | ||
this._store = store; | ||
this._ModelClass = ModelClass; | ||
this._Model = Model; | ||
} | ||
}, | ||
__getCreateSql: function (table, fields) { | ||
var _table = table, _fieldsSql = [], _field = null; | ||
for(var i = 0, _len = fields.length; i < _len; i++){ | ||
_field = fields[i]; | ||
_fieldsSql.push(_field); | ||
} | ||
var _sql = "DROP TABLE IF EXISTS "+_table+";"; | ||
var _sql = ""; | ||
_sql += "CREATE TABLE "+_table+" ("; | ||
_sql += _fieldsSql.join(','); | ||
_sql += ") ENGINE=innodb DEFAULT CHARSET=utf8;"; | ||
return _sql; | ||
beginTransaction: function (){ | ||
return this._store.beginTransaction(); | ||
}, | ||
create: function (table, fields){ | ||
return this._store.execCommand(this.__getCreateSql(table, fields)); | ||
insert: function (values){ | ||
return this._store.query(this._Model.getInsertSql({ values: values })); | ||
}, | ||
desc: function (table){ | ||
return this._store.execCommand('DESC ' + table); | ||
select: function (argv){ | ||
return this._store.query(this._Model.getSelectSql(argv)); | ||
}, | ||
drop: function (table){ | ||
return this._store.execCommand('DROP TABLE ' + table); | ||
selectOne: function (argv){ | ||
var _defer = zn.async.defer(); | ||
this.select(argv) | ||
.then(function (rows){ | ||
_defer.resolve(rows[0]); | ||
}, function (error){ | ||
_defer.reject(error); | ||
}); | ||
return _defer.promise; | ||
}, | ||
show: function (){ | ||
return this._store.execCommand('SHOW TABLES;'); | ||
paging: function (argv){ | ||
return this._store.query(this._Model.getPagingSql(argv)); | ||
}, | ||
addField: function (table, field){ | ||
return this._store.execCommand('ALTER TABLE ' + table + ' ADD ' + field + ';'); | ||
update: function (updates, where){ | ||
return this._store.query(this._Model.getUpdateSql({ updates: updates, where: where })); | ||
}, | ||
modifyField: function (table, field) { | ||
return this._store.execCommand('ALTER TABLE ' + table + ' MODIFY ' + field + ';'); | ||
}, | ||
dropField: function (table, field){ | ||
this._store.execCommand('ALTER TABLE ' + table + ' DROP ' + field + ';'); | ||
}, | ||
usedb: function (db) { | ||
this._store.setDataBase(db); | ||
delete: function (where){ | ||
return this._store.query(this._Model.getDeleteSql({ where : where })); | ||
} | ||
@@ -58,6 +73,5 @@ } | ||
var _args = arguments, | ||
_name = _args[0], | ||
_meta = _args[1]; | ||
_meta = _args[0]; | ||
return zn.Class(_name, Collection, _meta); | ||
return zn.Class(Collection, _meta); | ||
} | ||
@@ -64,0 +78,0 @@ |
zn.define([ | ||
'./Model', | ||
'./Action', | ||
'./ModelSql', | ||
'./Collection', | ||
'./Store' | ||
]); |
@@ -6,3 +6,8 @@ /** | ||
var SQLS = { | ||
CREATE: 'DROP TABLE IF EXISTS {table};CREATE TABLE {table} ({fields}) ENGINE=innodb DEFAULT CHARSET=utf8;' | ||
}; | ||
var Model = zn.Class('zn.db.data.Model', { | ||
partial: true, | ||
statics: { | ||
@@ -12,61 +17,27 @@ getTable: function (){ | ||
}, | ||
getFields: function (ifFilterPrimary, onCheckItem) { | ||
var _properties = this.getProperties(); | ||
var _fields = [], | ||
_self = this, | ||
_onCheckItem = onCheckItem||function (){}; | ||
for(var _key in _properties){ | ||
var _property = _properties[_key]; | ||
_onCheckItem(_property, _key); | ||
if(!ifFilterPrimary){ | ||
var _format = _property.format; | ||
if(_format){ | ||
_property.alias = _format.replace(/\{\}/g, _key)+' as '+_key; | ||
} | ||
var _convert = _property.convert; | ||
if(_convert){ | ||
_fields.push(_convert.replace(/\{\}/g, _key)+' as '+_key+'_convert'); | ||
} | ||
} | ||
_key = _property.alias||_key; | ||
if(_property.primary){ | ||
_self._primary = _key; | ||
if(ifFilterPrimary){ | ||
continue; | ||
} | ||
_fields.unshift(_key); | ||
getCreateSql: function (){ | ||
var _fields = []; | ||
this.getProperties(function (prop, key){ | ||
prop.name = key; | ||
var _sql = this.__getPropertyCreateSql(prop); | ||
if(props.primary){ | ||
_fields.unshift(_sql); | ||
}else { | ||
_fields.push(_key); | ||
_fields.push(_sql); | ||
} | ||
} | ||
return _fields; | ||
}, | ||
getCreateSql: function (){ | ||
var _table = this.getTable(), | ||
_fieldsSql = [], | ||
_self = this; | ||
return false; | ||
}, this); | ||
this.getFields(false, function (property, key){ | ||
var _propertySql = _self.__propertyToCreateSql(property, key); | ||
if(key=='id'){ | ||
_fieldsSql.unshift(_propertySql); | ||
}else { | ||
_fieldsSql.push(_propertySql); | ||
} | ||
return SQLS.CREATE.format({ | ||
table: this.getTable(), | ||
fields: _fields.join(',') | ||
}); | ||
var _sql = "DROP TABLE IF EXISTS "+_table+";"; | ||
//var _sql = ""; | ||
_sql += "CREATE TABLE "+_table+" ("; | ||
_sql += _fieldsSql.join(','); | ||
_sql += ") ENGINE=innodb DEFAULT CHARSET=utf8;"; | ||
return _sql; | ||
}, | ||
__propertyToCreateSql: function (property, key){ | ||
var _keys = [key], | ||
_typeAry = property.type, | ||
_t1 = _typeAry[0], | ||
_t2 = _typeAry[1]; | ||
__getPropertyCreateSql: function (property){ | ||
var _key = property.name, | ||
_type = prototype.type || [], | ||
_t1 = _type[0], | ||
_t2 = _type[1], | ||
_keys = [_key]; | ||
@@ -84,4 +55,5 @@ _keys.push(_t1+(_t2?'('+_t2+')':'')); | ||
} | ||
var _default = this.__getDefaultValue(property, key); | ||
var _default = this.__getPropertyDefaultValue(property); | ||
if(_default){ | ||
@@ -98,11 +70,10 @@ _keys.push(_default); | ||
}, | ||
__getDefaultValue: function (property, key) { | ||
__getPropertyDefaultValue: function (property) { | ||
if(property.default !== undefined){ | ||
var _type = property.type[0].toLowerCase(), | ||
_value = property.default; | ||
var _value = property.default; | ||
if(zn.is(_value, 'function')){ | ||
_value = _value.call(this, property, key); | ||
_value = _value.call(this, property, property.name); | ||
} | ||
switch(_type){ | ||
switch(property.type[0].toLowerCase()){ | ||
case 'nvarchar': | ||
@@ -112,4 +83,4 @@ case 'varchar': | ||
case 'char': | ||
_value = _value || ''; | ||
if(zn.is(_value, 'string')){ | ||
/* | ||
if(_value.indexOf('{') === 0 && _value.indexOf('}') === (_value.length-1)){ | ||
@@ -119,4 +90,3 @@ _value = _value.substring(1, _value.length-1); | ||
_value = "'" + _value + "'"; | ||
}*/ | ||
_value = "'" + _value + "'"; | ||
} | ||
} | ||
@@ -128,3 +98,3 @@ break; | ||
case 'int': | ||
_value = _value==null?0:_value; | ||
break; | ||
@@ -134,7 +104,18 @@ } | ||
return 'DEFAULT '+_value; | ||
}else { | ||
return null; | ||
} | ||
} | ||
}, | ||
properties: { | ||
table: { | ||
get: function (){ | ||
return this._table; | ||
} | ||
}, | ||
props: { | ||
get: function (){ | ||
return this._props; | ||
} | ||
} | ||
}, | ||
methods: { | ||
@@ -145,52 +126,5 @@ init: { | ||
this._table = this.constructor.getTable(); | ||
this._fields = this.constructor.getFields(); | ||
this._props = this.constructor.getProperties(); | ||
this.sets(args); | ||
} | ||
}, | ||
__getInsertFieldsValues: function () { | ||
var _kAry = [], | ||
_vAry = [], | ||
_self = this; | ||
this.constructor.getFields(true, function (field, key){ | ||
var _value = this.get(key); | ||
if(zn.is(_value, 'object')){ | ||
_value = _value.value; | ||
} | ||
if(_value === undefined || _value === null){ | ||
var _default = field.default; | ||
if(zn.is(_default, 'function')){ | ||
_default = _default.call(_self, field, key); | ||
} | ||
_value = _default; | ||
} | ||
if(_value !== null && !field.ignore){ | ||
_kAry.push(key); | ||
_vAry.push(_value); | ||
} | ||
}.bind(this)); | ||
return [_kAry, _vAry]; | ||
}, | ||
__getUpdateFieldsValues: function () { | ||
var _self = this, | ||
_updates = {}; | ||
this.constructor.getFields(true, function (field, key){ | ||
var _value = _self.get(key); | ||
if(_value===undefined||_value===null){ | ||
_value = _self.__formatAutoUpdate(field.auto_update); | ||
} | ||
if(_value!=null){ | ||
_updates[key] = _value; | ||
} | ||
}); | ||
return _updates; | ||
}, | ||
__formatAutoUpdate: function (auto_update){ | ||
switch(zn.type(auto_update)){ | ||
case 'date': | ||
return auto_update.toString(); | ||
case 'string': | ||
return auto_update; | ||
} | ||
} | ||
@@ -197,0 +131,0 @@ } |
@@ -6,3 +6,110 @@ /** | ||
return zn.Class({ | ||
return zn.Class('zn.db.data.Model', { | ||
partial: true, | ||
statics: { | ||
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); | ||
} | ||
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 (fields){ | ||
fields = fields; | ||
var _props = this.getProperties(); | ||
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){ | ||
if(typeof index == 'string'){ | ||
_fields.push(field + ' as ' + index); | ||
}else { | ||
_prop = _props[field]; | ||
if(!_prop){ | ||
return false; | ||
} | ||
_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'); | ||
argv.fields = this.getSelectFields(argv.fields); | ||
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); | ||
} | ||
}, | ||
methods: { | ||
@@ -9,0 +116,0 @@ |
/** | ||
* Created by yangyxu on 9/17/14. | ||
*/ | ||
zn.define([ | ||
'../mysql/MySqlCommand', | ||
'../sql/Transaction', | ||
'node:mysql' | ||
],function (MySqlCommand, Transaction, mysql) { | ||
zn.define(['../schema/ConnectionPool'], function (ConnectionPool) { | ||
var Store = zn.Class('zn.db.data.Store', { | ||
return zn.Class('zn.db.data.Store', { | ||
statics: { | ||
@@ -16,10 +12,2 @@ getStore: function (config) { | ||
}, | ||
properties: { | ||
command: { | ||
readonly: true, | ||
get: function (){ | ||
return new this._commandClass(this._pool); | ||
} | ||
} | ||
}, | ||
methods: { | ||
@@ -29,67 +17,14 @@ init: { | ||
value: function (inConfig){ | ||
this._config = inConfig || {}; | ||
switch (inConfig.type.toLowerCase()) { | ||
case 'mysql': | ||
this._pool = mysql.createPool(zn.extend({ | ||
"dateStrings": true, | ||
"multipleStatements": true | ||
}, inConfig)); | ||
this._commandClass = MySqlCommand; | ||
break; | ||
case 'mongo': | ||
break; | ||
} | ||
this._pool = ConnectionPool.getPool(inConfig || {}); | ||
} | ||
}, | ||
beginTransaction: function (){ | ||
return (new Transaction(this._pool)).begin(); | ||
return this._pool.beginTransaction(); | ||
}, | ||
setDataBase: function (value){ | ||
this._config.database = value; | ||
query: function (){ | ||
return this._pool.query.apply(this._pool, arguments); | ||
}, | ||
setup: function (){ | ||
var _defer = zn.async.defer(); | ||
var _sql = 'drop database if exists ' + this._config.database + ';' | ||
_sql += 'create database if not exists ' + this._config.database + ';'; | ||
var _config = zn.extend({}, this._config); | ||
_config.database = null; | ||
delete _config.database; | ||
_config.dateStrings = true; | ||
_config.multipleStatements = true; | ||
zn.info(_sql); | ||
var connection = mysql.createConnection(_config).query(_sql, function (err, rows){ | ||
if(err){ | ||
_defer.reject(err); | ||
}else { | ||
_defer.resolve(rows); | ||
} | ||
}); | ||
return _defer.promise; | ||
createModel: function (ModelClass) { | ||
return this._pool.query(ModelClass.getCreateSql()); | ||
}, | ||
create: function (){ | ||
}, | ||
drop: function (){ | ||
return this.query('DROP DATABASE ' + name); | ||
}, | ||
show: function (){ | ||
return this.query('SHOW DATABASES;'); | ||
}, | ||
query: function (sql){ | ||
return this.command.query.apply(this, arguments); | ||
}, | ||
paging: function (){ | ||
return this.command.paging.apply(this, arguments); | ||
}, | ||
createModel: function (inModelClass) { | ||
var _defer = zn.async.defer(); | ||
this.command.query(inModelClass.getCreateSql()) | ||
.then(function (data, command){ | ||
_defer.resolve(data); | ||
command.release(); | ||
}); | ||
return _defer.promise; | ||
}, | ||
createModels: function (models){ | ||
@@ -111,3 +46,3 @@ var _tran = this.beginTransaction(), | ||
}).on('finally', function (sender, data){ | ||
_defer.reject(data); | ||
_defer.resolve(data); | ||
}).commit(); | ||
@@ -120,6 +55,2 @@ | ||
zn.Store = Store; | ||
return Store; | ||
}); |
zn.define([ | ||
'./data/', | ||
'./common/', | ||
'./sql/', | ||
'./mysql/ZNSql' | ||
], function (data, common, sql, ZNSql) { | ||
'./schema/' | ||
], function (data, common, schema) { | ||
return { | ||
data: data, | ||
common: common | ||
common: common, | ||
schema: schema | ||
} | ||
}); |
@@ -17,3 +17,3 @@ /** | ||
return zn.Class('StringFilter', Filter, { | ||
return zn.Class(Filter, { | ||
properties: { | ||
@@ -20,0 +20,0 @@ |
@@ -28,3 +28,3 @@ /** | ||
this._models = {}; | ||
this._actions = {}; | ||
this._collections = {}; | ||
this._controllers = {}; | ||
@@ -67,10 +67,10 @@ this._appContexts= {}; | ||
}, | ||
getActions: function (){ | ||
var _actions = {}; | ||
zn.extend(_actions, this._actions); | ||
getCollections: function (){ | ||
var _collections = {}; | ||
zn.extend(_collections, this._collections); | ||
zn.each(this._appContexts, function (appContext, index){ | ||
zn.extend(_actions, appContext.getActions()); | ||
zn.extend(_collections, appContext.getCollections()); | ||
}); | ||
return _actions; | ||
return _collections; | ||
}, | ||
@@ -86,4 +86,4 @@ registerApplicationContext: function (appContext){ | ||
}, | ||
registerActions: function (actions){ | ||
return zn.extend(this._actions, actions), this; | ||
registerCollections: function (collections){ | ||
return zn.extend(this._collections, collections), this; | ||
}, | ||
@@ -139,3 +139,3 @@ registerControllers: function (controllers){ | ||
zn.each((databaseSetting || []), function (config, index){ | ||
_store = zn.Store.getStore(config); | ||
_store = zn.db.data.Store.getStore(config); | ||
_stores[index] = _store; | ||
@@ -142,0 +142,0 @@ if(config.default){ |
@@ -12,20 +12,33 @@ zn.define(function () { | ||
this._store = context._store; | ||
this._collections = {}; | ||
} | ||
}, | ||
action: { | ||
collection: { | ||
router: null, | ||
value: function (model, store){ | ||
var _store = store || this._store; | ||
var _key = model; | ||
if(typeof model !== 'string'){ | ||
_key = model.getTable(); | ||
} | ||
var _ctor = this._context._actions[_key]; | ||
if(_ctor){ | ||
return new _ctor(_store, _ctor.getMeta('model')); | ||
value: function (model){ | ||
if(this._collections[model]){ | ||
return this._collections[model]; | ||
}else { | ||
throw new Error('Arguments Error: The action for ' + _key + ' is not exist!'); | ||
var _ctor = this._context.parentContext._collections[model]; | ||
if(_ctor){ | ||
this._collections[model] = new _ctor(this._store, _ctor.getMeta('model')); | ||
return this._collections[model]; | ||
}else { | ||
throw new Error('Arguments Error: The collection for ' + model + ' is not exist!'); | ||
} | ||
} | ||
} | ||
}, | ||
beginTransaction: { | ||
router: null, | ||
value: function (model, store){ | ||
return this._store.beginTransaction(); | ||
} | ||
}, | ||
query: { | ||
router: null, | ||
value: function (){ | ||
return this._store.query.call(this, arguments); | ||
} | ||
}, | ||
store: { | ||
@@ -32,0 +45,0 @@ router: null, |
@@ -28,3 +28,3 @@ /** | ||
}catch(e){ | ||
zn.error(e.message); | ||
zn.error('RestfulRequestHandler doRequest error: ', e.message); | ||
console.log(e.stack); | ||
@@ -31,0 +31,0 @@ return response.forword('__zn__/error/__404'); |
@@ -53,3 +53,3 @@ /** | ||
if(_parentPaths.length){ | ||
process.env.NODE_PATH = process.env.NODE_PATH + node_path.delimiter + _parentPaths.join(node_path.delimiter); | ||
process.env.NODE_PATH = _parentPaths.join(node_path.delimiter) + node_path.delimiter + process.env.NODE_PATH; | ||
module.constructor._initPaths(); | ||
@@ -105,3 +105,3 @@ zn.NODE_PATHS = process.env.NODE_PATH.split(node_path.delimiter); | ||
this.fire('close', this); | ||
Logger.info("close zeanium-server"); | ||
zn.info("zeanium-server has closed."); | ||
} | ||
@@ -108,0 +108,0 @@ } |
@@ -48,2 +48,3 @@ /** | ||
this._routers = {}; | ||
this._collections = {}; | ||
this._changedFiles = []; | ||
@@ -119,3 +120,5 @@ this._uuid = zn.uuid(); | ||
app.parentContext = this; | ||
zn.extend(this._routers, app._routers); | ||
zn.extend(this._collections, app._collections); | ||
//console.log(Object.keys(this._routers)); | ||
@@ -122,0 +125,0 @@ //app.fire('register', this); |
zn.define({ | ||
deploy: 'app', | ||
models: '/src/model/', | ||
controllers: '/src/controller/', | ||
views: { | ||
path: '/src/view/', | ||
suffix: 'html' | ||
}, | ||
session: { | ||
cookie: { | ||
maxAge: 60 * 60 * 1000, | ||
path: '/', | ||
expires: '', | ||
httpOnly: true, | ||
secure: false | ||
} | ||
} | ||
controllers: '/src/controller/' | ||
}); |
@@ -23,3 +23,7 @@ /** | ||
chain: null, | ||
session: null, | ||
session: { | ||
get: function (){ | ||
return this._session; | ||
} | ||
}, | ||
serverRequest: { | ||
@@ -53,2 +57,15 @@ value: null, | ||
}, | ||
getSessionKeyValue: function (sessionKey, key){ | ||
var _session = this._session, | ||
_sessionKey = sessionKey || '@AdminUser'; | ||
if(_session.hasItem()){ | ||
if(_session.getItem(_sessionKey)){ | ||
return _session.getItem(_sessionKey)[key]||0; | ||
}else { | ||
return 0; | ||
} | ||
}else { | ||
return 0; | ||
} | ||
}, | ||
getJSON: function (inName){ | ||
@@ -55,0 +72,0 @@ var _value = this.getValue(inName); |
@@ -176,3 +176,3 @@ /** | ||
__models = {}, | ||
__actions = {}, | ||
__collections = {}, | ||
__controllers= {}; | ||
@@ -185,3 +185,3 @@ | ||
_items = {}, | ||
_action = null, | ||
_collection = null, | ||
_table = null, | ||
@@ -197,8 +197,8 @@ _name = null; | ||
_name = _item.$path.split(zn.SLASH).pop().split('.').shift(); | ||
_action = _self.getAction(_item); | ||
_table = _item.getTable(); | ||
__actions[key] = __actions[_name] = _action; | ||
_collection = _self.getCollection(_item); | ||
_table = _item.getMeta('table'); | ||
__collections[key] = __collections[_name] = _collection; | ||
_items[_name] = _item; | ||
if(_table){ | ||
__actions[_table] = _action; | ||
__collections[_table] = _collection; | ||
} | ||
@@ -213,3 +213,3 @@ } | ||
applicationContext.registerModels(__models); | ||
applicationContext.registerActions(__actions); | ||
applicationContext.registerCollections(__collections); | ||
applicationContext.registerControllers(__controllers); | ||
@@ -223,20 +223,20 @@ applicationContext.doLoaded(); | ||
}, | ||
getAction: function (ModelClass) { | ||
var _actions = []; | ||
this.__getModelActions(ModelClass, _actions); | ||
return zn.Action({ | ||
getCollection: function (ModelClass) { | ||
var _collections = []; | ||
this.__getModelCollections(ModelClass, _collections); | ||
return zn.Collection({ | ||
model: ModelClass, | ||
mixins: _actions | ||
mixins: _collections | ||
}); | ||
}, | ||
__getModelActions: function (ModelClass, actions){ | ||
__getModelCollections: function (ModelClass, collections){ | ||
var _mixin = null, | ||
_action = ModelClass.getMeta('action'), | ||
_collection = ModelClass.getMeta('collection'), | ||
_mixins_ = ModelClass._mixins_; | ||
if(_action){ | ||
actions.push(_action); | ||
if(_collection){ | ||
collections.push(_collection); | ||
} | ||
for(var _i = 0, _len = _mixins_.length; _i < _len; _i++){ | ||
this.__getModelActions(_mixins_[_i], actions); | ||
this.__getModelCollections(_mixins_[_i], collections); | ||
} | ||
@@ -243,0 +243,0 @@ } |
@@ -1,2 +0,2 @@ | ||
line.module({ | ||
zn.define({ | ||
host: '127.0.0.1', | ||
@@ -6,2 +6,2 @@ port: 8000, | ||
mode: 'release' //release, debug, view | ||
}); | ||
}); |
@@ -7,5 +7,2 @@ /** | ||
return zn.Class('MemorySessionManager', SessionManager, { | ||
properties: { | ||
}, | ||
methods: { | ||
@@ -12,0 +9,0 @@ init: function (config){ |
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
248329
125
5900
180
Updatedzeanium@^1.1.16