Merge pull request #24 from Geeknux/master

Add some new features to advance query in Mysql
This commit is contained in:
1602 2012-02-20 10:32:09 -08:00
commit 96459bfdcd
1 changed files with 42 additions and 20 deletions

View File

@ -104,6 +104,12 @@ 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;
@ -219,8 +225,17 @@ MySQL.prototype.all = function all(model, filter, callback) {
case 'between':
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);
@ -398,17 +413,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;
}