Skip to content

Commit 148426a

Browse files
committed
feat(defaultValue): add support for timestamps and add internal handling
Signed-off-by: Tobias Gurtzick <[email protected]>
1 parent f102362 commit 148426a

File tree

4 files changed

+223
-122
lines changed

4 files changed

+223
-122
lines changed

index.js

+29-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ var Sqlite3Driver = Base.extend({
1515
this.connection = connection;
1616
},
1717

18+
_translateSpecialDefaultValues: function (
19+
spec,
20+
options,
21+
tableName,
22+
columnName
23+
) {
24+
switch (spec.defaultValue.special) {
25+
case 'CURRENT_TIMESTAMP':
26+
spec.defaultValue.prep = 'CURRENT_TIMESTAMP';
27+
break;
28+
default:
29+
this.super(spec, options, tableName, columnName);
30+
break;
31+
}
32+
},
33+
1834
createDatabase: function (cb) {
1935
// sqlite does this automatically if needed
2036
return Promise.resolve(null).nodeify(cb);
@@ -84,7 +100,11 @@ var Sqlite3Driver = Base.extend({
84100

85101
if (typeof spec.defaultValue === 'string') {
86102
constraint.push('"' + spec.defaultValue + '"');
87-
} else constraint.push(spec.defaultValue);
103+
} else if (typeof spec.defaultValue.prep === 'string') {
104+
constraint.push(spec.defaultValue.prep);
105+
} else {
106+
constraint.push(spec.defaultValue);
107+
}
88108
}
89109

90110
return constraint.join(' ');
@@ -139,9 +159,15 @@ var Sqlite3Driver = Base.extend({
139159
},
140160

141161
all: function () {
142-
this.log.sql.apply(null, arguments);
162+
var params = arguments;
163+
164+
this.log.sql.apply(null, params);
143165

144-
this.connection.all.apply(this.connection, arguments);
166+
return new Promise((resolve, reject) => {
167+
this.connection.all(params[0], function (err, result) {
168+
return err ? reject(err) : resolve(result);
169+
});
170+
}).nodeify(params[1]);
145171
},
146172

147173
close: function (callback) {

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"homepage": "https://github.com/db-migrate/sqlite",
3131
"dependencies": {
3232
"bluebird": "^3.1.1",
33-
"db-migrate-base": "^1.2.5",
33+
"db-migrate-base": "^1.6.3",
3434
"sqlite3": "^4.0.1"
3535
},
3636
"devDependencies": {

0 commit comments

Comments
 (0)