Comparing version 0.0.15 to 0.0.17
@@ -15,5 +15,6 @@ var Where = require("./Where"); | ||
var sql = { | ||
from : [], | ||
where : [], | ||
order : [] | ||
from : [], | ||
where : [], | ||
order : [], | ||
group_by : null | ||
}; | ||
@@ -129,2 +130,6 @@ var get_table_alias = function (table) { | ||
}, | ||
groupBy: function () { | ||
sql.group_by = Array.prototype.slice.apply(arguments); | ||
return this; | ||
}, | ||
offset: function (offset) { | ||
@@ -156,77 +161,54 @@ sql.offset = offset; | ||
sql.from[i].a = "t" + (i + 1); | ||
if (sql.from[i].select && typeof sql.from[i].select[0] == "object") { | ||
continue; | ||
} | ||
if (sql.from[i].select) { | ||
select_all = false; | ||
break; | ||
} | ||
} | ||
if (select_all) { | ||
tmp = []; | ||
for (i = 0; i < sql.from.length; i++) { | ||
if (!sql.from[i].select) continue; | ||
if (typeof sql.from[i].select[0] != "object") continue; | ||
for (j = 0; j < sql.from[i].select.length; j++) { | ||
str = sql.from[i].select[j].f + "("; | ||
tmp = []; | ||
for (i = 0; i < sql.from.length; i++) { | ||
if (!sql.from[i].select) continue; | ||
// if (typeof sql.from[i].select[0] != "object") continue; | ||
if (sql.from[i].select[j].c && !Array.isArray(sql.from[i].select[j].c)) { | ||
sql.from[i].select[j].c = [ sql.from[i].select[j].c ]; | ||
} | ||
if (Array.isArray(sql.from[i].select[j].c)) { | ||
str += sql.from[i].select[j].c.map(function (el) { | ||
if (typeof el != "string") { | ||
return el; | ||
} | ||
if (sql.from.length == 1) { | ||
return Dialect.escapeId(el); | ||
} else { | ||
return Dialect.escapeId(sql.from[i].a, el); | ||
} | ||
}).join(", "); | ||
for (j = 0; j < sql.from[i].select.length; j++) { | ||
if (typeof sql.from[i].select[j] == "string") { | ||
if (sql.from.length == 1) { | ||
tmp.push(Dialect.escapeId(sql.from[i].select[j])); | ||
} else { | ||
str += "*"; | ||
tmp.push(Dialect.escapeId(sql.from[i].a, sql.from[i].select[j])); | ||
} | ||
continue; | ||
} | ||
str = sql.from[i].select[j].f + "("; | ||
str += ")"; | ||
str += (sql.from[i].select[j].a ? " AS " + Dialect.escapeId(sql.from[i].select[j].a) : ""); | ||
if (sql.from[i].select[j].c && !Array.isArray(sql.from[i].select[j].c)) { | ||
sql.from[i].select[j].c = [ sql.from[i].select[j].c ]; | ||
} | ||
if (sql.from[i].select[j].s.length > 0) { | ||
str = sql.from[i].select[j].s.join("(") + "(" + str + | ||
((new Array(sql.from[i].select[j].s.length + 1)).join(")")); | ||
} | ||
if (Array.isArray(sql.from[i].select[j].c)) { | ||
str += sql.from[i].select[j].c.map(function (el) { | ||
if (typeof el != "string") { | ||
return el; | ||
} | ||
if (sql.from.length == 1) { | ||
return Dialect.escapeId(el); | ||
} else { | ||
return Dialect.escapeId(sql.from[i].a, el); | ||
} | ||
}).join(", "); | ||
} else { | ||
str += "*"; | ||
} | ||
tmp.push(str); | ||
str += ")"; | ||
str += (sql.from[i].select[j].a ? " AS " + Dialect.escapeId(sql.from[i].select[j].a) : ""); | ||
if (sql.from[i].select[j].s.length > 0) { | ||
str = sql.from[i].select[j].s.join("(") + "(" + str + | ||
((new Array(sql.from[i].select[j].s.length + 1)).join(")")); | ||
} | ||
tmp.push(str); | ||
} | ||
if (tmp.length) { | ||
query.push(tmp.join(", ")); | ||
} else { | ||
query.push("*"); | ||
} | ||
} | ||
if (tmp.length) { | ||
query.push(tmp.join(", ")); | ||
} else { | ||
tmp = []; | ||
for (i = 0; i < sql.from.length; i++) { | ||
if (!sql.from[i].select) { | ||
if (sql.from.length == 1) { | ||
tmp.push("*"); | ||
} else { | ||
tmp.push(Dialect.escapeId(sql.from[i].a) + ".*"); | ||
} | ||
} else { | ||
if (sql.from.length == 1) { | ||
sql.from[i].select.map(function (col) { | ||
tmp.push(Dialect.escapeId(col)); | ||
}.bind(this)); | ||
} else { | ||
sql.from[i].select.map(function (col) { | ||
tmp.push(Dialect.escapeId(sql.from[i].a, col)); | ||
}.bind(this)); | ||
} | ||
} | ||
} | ||
query.push(tmp.join(", ")); | ||
query.push("*"); | ||
} | ||
@@ -267,2 +249,12 @@ | ||
if (sql.group_by !== null) { | ||
query.push("GROUP BY " + sql.group_by.map(function (column) { | ||
if (column[0] == "-") { | ||
sql.order.unshift({ c: column.substr(1), d: "DESC" }); | ||
return Dialect.escapeId(column.substr(1)); | ||
} | ||
return Dialect.escapeId(column); | ||
}).join(", ")); | ||
} | ||
// order | ||
@@ -269,0 +261,0 @@ if (sql.order.length > 0) { |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "0.0.15", | ||
"version": "0.0.17", | ||
"license": "MIT", | ||
@@ -12,0 +12,0 @@ "repository": { |
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
32817
32
1144