Skip to content

Commit cc4223b

Browse files
committed
Allow custom named properties and custom selects
1 parent 74f813c commit cc4223b

File tree

5 files changed

+44
-26
lines changed

5 files changed

+44
-26
lines changed

lib/Dialects/mysql.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
var util = require("util");
22
var helpers = require("../Helpers");
33

4+
exports.escape = function (query, args) {
5+
return helpers.escapeQuery(exports, query, args);
6+
}
7+
48
exports.escapeId = function () {
59
return Array.prototype.slice.apply(arguments).map(function (el) {
610
if (typeof el == "object") {

lib/Dialects/postgresql.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
var util = require("util");
22
var helpers = require("../Helpers");
33

4+
exports.escape = function (query, args) {
5+
return helpers.escapeQuery(exports, query, args);
6+
}
7+
48
exports.escapeId = function () {
59
return Array.prototype.slice.apply(arguments).map(function (el) {
610
if (typeof el == "object") {

lib/Dialects/sqlite.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
var util = require("util");
22
var helpers = require("../Helpers");
33

4+
exports.escape = function (query, args) {
5+
return helpers.escapeQuery(exports, query, args);
6+
}
7+
48
exports.escapeId = require("./mysql").escapeId;
59

610
exports.escapeVal = function (val, timeZone) {

lib/Select.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -247,38 +247,44 @@ function SelectQuery(Dialect, opts) {
247247
continue;
248248
}
249249

250-
if (!sql.from[i].select[j].f) continue;
251-
252250
str = sql.from[i].select[j].f + "(";
253251

254-
if (sql.from[i].select[j].c && !Array.isArray(sql.from[i].select[j].c)) {
255-
sql.from[i].select[j].c = [ sql.from[i].select[j].c ];
256-
}
252+
if (sql.from[i].select[j].f) {
253+
str = sql.from[i].select[j].f + "(";
254+
255+
if (sql.from[i].select[j].c && !Array.isArray(sql.from[i].select[j].c)) {
256+
sql.from[i].select[j].c = [ sql.from[i].select[j].c ];
257+
}
257258

258-
if (Array.isArray(sql.from[i].select[j].c)) {
259-
str += sql.from[i].select[j].c.map(function (el) {
260-
if (typeof el.type == "function") {
261-
switch (el.type()) {
262-
case "text":
263-
return Dialect.escapeVal(el.data, opts.timezone);
264-
default:
265-
return el;
259+
if (Array.isArray(sql.from[i].select[j].c)) {
260+
str += sql.from[i].select[j].c.map(function (el) {
261+
if (typeof el.type == "function") {
262+
switch (el.type()) {
263+
case "text":
264+
return Dialect.escapeVal(el.data, opts.timezone);
265+
default:
266+
return el;
267+
}
266268
}
267-
}
268-
if (typeof el != "string") {
269-
return el;
270-
}
271-
if (sql.from.length == 1) {
272-
return Dialect.escapeId(el);
273-
} else {
274-
return Dialect.escapeId(sql.from[i].a, el);
275-
}
276-
}).join(", ");
269+
if (typeof el != "string") {
270+
return el;
271+
}
272+
if (sql.from.length == 1) {
273+
return Dialect.escapeId(el);
274+
} else {
275+
return Dialect.escapeId(sql.from[i].a, el);
276+
}
277+
}).join(", ");
278+
} else {
279+
str += "*";
280+
}
281+
str += ")";
282+
} else if (sql.from[i].select[j].sql) {
283+
str = '(' + sql.from[i].select[j].sql + ')';
277284
} else {
278-
str += "*";
285+
continue;
279286
}
280287

281-
str += ")";
282288
str += (sql.from[i].select[j].a ? " AS " + Dialect.escapeId(sql.from[i].select[j].a) : "");
283289

284290
if (sql.from[i].select[j].s && sql.from[i].select[j].s.length > 0) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"sql",
77
"query"
88
],
9-
"version": "0.1.16",
9+
"version": "0.1.17",
1010
"license": "MIT",
1111
"repository": {
1212
"url": "http://github.com/dresende/node-sql-query"

0 commit comments

Comments
 (0)