Merge branch 'master' of github.com:1602/jugglingdb

This commit is contained in:
Anatoliy Chakkaev 2012-02-20 22:33:28 +04:00
commit 11b4436fd1
2 changed files with 45 additions and 21 deletions

View File

@ -104,7 +104,13 @@ MySQL.prototype.toDatabase = function (prop, val) {
return this.toDatabase(prop, val[0]) +
' AND ' +
this.toDatabase(prop, val[1]);
}
} else if (operator == 'inq' || operator == 'nin') {
if (!(val.propertyIsEnumerable('length')) && typeof val === 'object' && typeof val.length === 'number') { //if value is array
return val.join(',');
} else {
return val;
}
}
}
if (prop.type.name === 'Number') return val;
if (prop.type.name === 'Date') {
@ -205,22 +211,31 @@ MySQL.prototype.all = function all(model, filter, callback) {
var sqlCond = keyEscaped;
switch (condType) {
case 'gt':
sqlCond += ' > ';
break;
sqlCond += ' > ';
break;
case 'gte':
sqlCond += ' >= ';
break;
sqlCond += ' >= ';
break;
case 'lt':
sqlCond += ' < ';
break;
sqlCond += ' < ';
break;
case 'lte':
sqlCond += ' <= ';
break;
sqlCond += ' <= ';
break;
case 'between':
sqlCond += ' BETWEEN ';
break;
sqlCond += ' BETWEEN ';
break;
case 'inq':
sqlCond += ' IN ';
break;
case 'nin':
sqlCond += ' NOT IN ';
break;
case 'neq':
sqlCond + ' != ';
break;
}
sqlCond += val;
sqlCond += (condType == 'inq' || condType == 'nin') ? '(' + val + ')' : val;
cs.push(sqlCond);
} else {
cs.push(keyEscaped + ' = ' + val);
@ -430,17 +445,24 @@ MySQL.prototype.propertySettingsSQL = function (model, prop) {
};
function datatype(p) {
var dt = '';
switch (p.type.name) {
case 'String':
return 'VARCHAR(' + (p.limit || 255) + ')';
dt = 'VARCHAR(' + (p.limit || 255) + ')';
break;
case 'Text':
return 'TEXT';
dt = 'TEXT';
break;
case 'Number':
return 'INT(11)';
dt = 'INT(' + (p.limit || 11) + ')';
break;
case 'Date':
return 'DATETIME';
dt = 'DATETIME';
break;
case 'Boolean':
return 'TINYINT(1)';
}
dt = 'TINYINT(1)';
break;
}
dt += (typeof p.default !== 'undefined') ? ' DEFAULT ' + p.default.toString() : '';
return dt;
}

View File

@ -243,8 +243,10 @@ BridgeToRedis.prototype.all = function all(model, filter, callback) {
orders = [filter.order];
}
orders.forEach(function (key) {
if (props[key].type.name !== 'Number' && props[key].type.name !== 'Date') {
allNumeric = false;
if (key !== 'id') {
if (props[key].type.name !== 'Number' && props[key].type.name !== 'Date') {
allNumeric = false;
}
}
sortCmd.push("BY", model + ":*->" + key);
});