Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/dialect/sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ Sqlite.prototype.visitFunctionCall = function (functionCall) {
format = "'%H'";
break;
}
var txt = 'strftime(' + format + ', ' + (nodes[0] + '') + ')';
var col = (nodes[0] + '');
if (_this.config.dateTimeMillis) {
// Convert to a datetime before running the strftime function
// Sqlite unix epoch is in seconds, but javascript is milliseconds.
col = 'datetime(' + col + '/1000, "unixepoch")';
}
var txt = 'strftime(' + format + ', ' + col + ')';
return txt;
}

Expand Down
14 changes: 10 additions & 4 deletions test/dialects/date-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ Harness.test({
string: 'SELECT EXTRACT(MONTH FROM "customer"."metadata") FROM "customer"'
},
sqlite: {
text : 'SELECT strftime(\'%m\', "customer"."metadata") FROM "customer"',
string: 'SELECT strftime(\'%m\', "customer"."metadata") FROM "customer"'
text: 'SELECT strftime(\'%m\', datetime("customer"."metadata"/1000, "unixepoch")) FROM "customer"',
string: 'SELECT strftime(\'%m\', datetime("customer"."metadata"/1000, "unixepoch")) FROM "customer"',
config: {
dateTimeMillis: true
}
},
mysql: {
text : 'SELECT MONTH(`customer`.`metadata`) FROM `customer`',
Expand Down Expand Up @@ -86,8 +89,11 @@ Harness.test({
string: 'SELECT EXTRACT(HOUR FROM "customer"."metadata") FROM "customer"'
},
sqlite: {
text : 'SELECT strftime(\'%H\', "customer"."metadata") FROM "customer"',
string: 'SELECT strftime(\'%H\', "customer"."metadata") FROM "customer"'
text: 'SELECT strftime(\'%H\', datetime("customer"."metadata"/1000, "unixepoch")) FROM "customer"',
string: 'SELECT strftime(\'%H\', datetime("customer"."metadata"/1000, "unixepoch")) FROM "customer"',
config: {
dateTimeMillis: true
}
},
mysql: {
text : 'SELECT HOUR(`customer`.`metadata`) FROM `customer`',
Expand Down