forked from dresende/node-sql-query
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsert.js
More file actions
35 lines (29 loc) · 718 Bytes
/
Insert.js
File metadata and controls
35 lines (29 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var Set = require("./Set");
exports.InsertQuery = InsertQuery;
function InsertQuery(Dialect, opts) {
var sql = {};
return {
into: function (table) {
sql.table = table;
return this;
},
set: function (values) {
sql.set = values;
return this;
},
build: function () {
var query = [], cols = [], vals = [];
query.push("INSERT INTO");
query.push(Dialect.escapeId(sql.table));
if (sql.hasOwnProperty("set")) {
for (var k in sql.set) {
cols.push(Dialect.escapeId(k));
vals.push(Dialect.escapeVal(sql.set[k], opts.timezone));
}
query.push("(" + cols.join(", ") + ")");
query.push("VALUES (" + vals.join(", ") + ")");
}
return query.join(" ");
}
};
}