Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sql-query

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql-query - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

47

lib/Remove.js

@@ -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;
}
};
}

2

package.json

@@ -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"
);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc