Skip to content

Commit 40a9850

Browse files
committed
Merge pull request dresende#37 from kapouer/defaultValues
Allow insertion of empty row using default values
2 parents 117ced2 + 926e497 commit 40a9850

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

lib/Dialects/mssql.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ exports.escapeVal = function (val, timeZone) {
6464

6565
return "'" + val.replace(/\'/g, "''") + "'";
6666
};
67+
68+
exports.defaultValuesStmt = "DEFAULT VALUES";

lib/Dialects/mysql.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@ function bufferToString(buffer) {
113113

114114
return "X'" + hex+ "'";
115115
}
116+
117+
exports.defaultValuesStmt = "VALUES()";

lib/Dialects/postgresql.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,5 @@ exports.escapeVal = function (val, timeZone) {
6565
// Google 'postgresql standard_conforming_strings' for details.
6666
return "'" + val.replace(/\'/g, "''") + "'";
6767
};
68+
69+
exports.defaultValuesStmt = "DEFAULT VALUES";

lib/Dialects/sqlite.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,5 @@ exports.escapeVal = function (val, timeZone) {
5454
// Google 'postgresql standard_conforming_strings' for details.
5555
return "'" + val.replace(/\'/g, "''") + "'";
5656
};
57+
58+
exports.defaultValuesStmt = "DEFAULT VALUES";

lib/Insert.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ function InsertQuery(Dialect, opts) {
2525
cols.push(Dialect.escapeId(k));
2626
vals.push(Dialect.escapeVal(sql.set[k], opts.timezone));
2727
}
28-
query.push("(" + cols.join(", ") + ")");
29-
query.push("VALUES (" + vals.join(", ") + ")");
28+
if (cols.length == 0) {
29+
query.push(Dialect.defaultValuesStmt);
30+
} else {
31+
query.push("(" + cols.join(", ") + ")");
32+
query.push("VALUES (" + vals.join(", ") + ")");
33+
}
3034
}
3135

3236
return query.join(" ");

0 commit comments

Comments
 (0)