不要怂,就是干,撸起袖子干!

Commit b2b4fa9b by Jason Jung Committed by Matt Broadstone

added support for delete

1 parent 6307f1dc
...@@ -189,7 +189,11 @@ module.exports = (function() { ...@@ -189,7 +189,11 @@ module.exports = (function() {
*/ */
/* istanbul ignore next */ /* istanbul ignore next */
deleteQuery: function(tableName, where, options) { deleteQuery: function(tableName, where, options) {
throwMethodUndefined('deleteQuery'); console.log('where:', where);
var query = SqlGenerator.deleteSql(tableName, where);
return query;
}, },
/* /*
......
...@@ -275,6 +275,16 @@ module.exports = { ...@@ -275,6 +275,16 @@ module.exports = {
return Utils._.template(query)(replacements); return Utils._.template(query)(replacements);
}, },
deleteSql: function(tableName, where) {
var query = "DELETE FROM <%= table %> <%= where %>";
var replacements = {
table: tableName,
where: this.getWhereClause(where, tableName)
};
return Utils._.template(query)(replacements);
},
addColumnSql: function(key, dataType){ addColumnSql: function(key, dataType){
var attribute = Utils._.template('<%= key %> <%= definition %>')({ var attribute = Utils._.template('<%= key %> <%= definition %>')({
key: quoteIdentifier(key), key: quoteIdentifier(key),
...@@ -546,13 +556,16 @@ module.exports = { ...@@ -546,13 +556,16 @@ module.exports = {
//console.log(where); //console.log(where);
//console.log(tableName); //console.log(tableName);
for(var key in where){ for(var key in where){
if(tableName){ var val = where[key];
query.push(quoteIdentifier(tableName) + '.' + quoteIdentifier(key)); var operator = '=';
}else{
query.push(quoteIdentifier(key)); if (val == 'NULL') {
operator = 'IS';
} }
query.push('=');
query.push(where[key]); query.push(quoteIdentifier(tableName) + '.' + quoteIdentifier(key));
query.push(operator);
query.push(val);
} }
return query.join(' '); return query.join(' ');
}}; }};
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!