Comparing version 0.1.7 to 0.1.8
@@ -7,3 +7,4 @@ var Where = require("./Where"); | ||
var sql = { | ||
where : [] | ||
where : [], | ||
order : [] | ||
}; | ||
@@ -26,3 +27,3 @@ | ||
build: function () { | ||
var query = []; | ||
var query = [], tmp; | ||
@@ -34,5 +35,47 @@ query.push("DELETE FROM"); | ||
// order | ||
if (sql.order.length > 0) { | ||
tmp = []; | ||
for (i = 0; i < sql.order.length; i++) { | ||
if (Array.isArray(sql.order[i].c)) { | ||
tmp.push(Dialect.escapeId.apply(Dialect, sql.order[i].c) + " " + sql.order[i].d); | ||
} else { | ||
tmp.push(Dialect.escapeId(sql.order[i].c) + " " + sql.order[i].d); | ||
} | ||
} | ||
if (tmp.length > 0) { | ||
query.push("ORDER BY " + tmp.join(", ")); | ||
} | ||
} | ||
// limit | ||
if (sql.hasOwnProperty("limit")) { | ||
if (sql.hasOwnProperty("offset")) { | ||
query.push("LIMIT " + sql.limit + " OFFSET " + sql.offset); | ||
} else { | ||
query.push("LIMIT " + sql.limit); | ||
} | ||
} else if (sql.hasOwnProperty("offset")) { | ||
query.push("OFFSET " + sql.offset); | ||
} | ||
return query.join(" "); | ||
}, | ||
offset: function (offset) { | ||
sql.offset = offset; | ||
return this; | ||
}, | ||
limit: function (limit) { | ||
sql.limit = limit; | ||
return this; | ||
}, | ||
order: function (column, dir) { | ||
sql.order.push({ | ||
c : Array.isArray(column) ? [ get_table_alias(column[0]), column[1] ] : column, | ||
d : (dir == "Z" ? "DESC" : "ASC") | ||
}); | ||
return this; | ||
} | ||
}; | ||
} |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"license": "MIT", | ||
@@ -12,0 +12,0 @@ "repository": { |
@@ -23,1 +23,21 @@ var common = require('../common'); | ||
); | ||
assert.equal( | ||
common.Remove().from('table1').limit(10).build(), | ||
"DELETE FROM `table1` LIMIT 10" | ||
); | ||
assert.equal( | ||
common.Remove().from('table1').limit(10).offset(3).build(), | ||
"DELETE FROM `table1` LIMIT 10 OFFSET 3" | ||
); | ||
assert.equal( | ||
common.Remove().from('table1').order('col').limit(5).build(), | ||
"DELETE FROM `table1` ORDER BY `col` ASC LIMIT 5" | ||
); | ||
assert.equal( | ||
common.Remove().from('table1').order('col1', 'A').order('col2', 'Z').limit(5).build(), | ||
"DELETE FROM `table1` ORDER BY `col1` ASC, `col2` DESC LIMIT 5" | ||
); |
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
45941
1538