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

Commit b2b4fa9b by Jason Jung Committed by Matt Broadstone

added support for delete

1 parent 6307f1dc
......@@ -189,7 +189,11 @@ module.exports = (function() {
*/
/* istanbul ignore next */
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 = {
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){
var attribute = Utils._.template('<%= key %> <%= definition %>')({
key: quoteIdentifier(key),
......@@ -546,13 +556,16 @@ module.exports = {
//console.log(where);
//console.log(tableName);
for(var key in where){
if(tableName){
query.push(quoteIdentifier(tableName) + '.' + quoteIdentifier(key));
}else{
query.push(quoteIdentifier(key));
var val = where[key];
var operator = '=';
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(' ');
}};
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!