Skip to content

Commit

Permalink
Unify object options handling for datetime/timestamp across dialects …
Browse files Browse the repository at this point in the history
…and update type definitions (#3181)

* Fix windows incompatiblity in npm scripts

* Update timestamp and datetime signature in oracle dialect to be consistent with other dialects
  • Loading branch information
lorefnon authored and kibertoad committed May 19, 2019
1 parent 08478f2 commit e2e044c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"debug:tape": "node --inspect-brk test/tape/index.js",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"dev": "rimraf ./lib && babel -w src --out-dir lib --copy-files",
"lint": "eslint '{src,test}/**/*.js'",
"lint": "eslint \"src/**/*.js\" \"test/**/*.js\"",
"lint:types": "dtslint types",
"prepare": "npm run babel",
"prepublishOnly": "npm run babel",
Expand Down
22 changes: 17 additions & 5 deletions src/dialects/oracledb/schema/columncompiler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const inherits = require('inherits');
const ColumnCompiler_Oracle = require('../../oracle/schema/columncompiler');

import { assign } from 'lodash';
import { assign, isObject } from 'lodash';

function ColumnCompiler_Oracledb() {
ColumnCompiler_Oracle.apply(this, arguments);
Expand All @@ -12,12 +12,24 @@ inherits(ColumnCompiler_Oracledb, ColumnCompiler_Oracle);
assign(ColumnCompiler_Oracledb.prototype, {
time: 'timestamp with local time zone',

datetime: function(without) {
return without ? 'timestamp' : 'timestamp with local time zone';
datetime: function(withoutTz) {
let useTz;
if (isObject(withoutTz)) {
({ useTz } = withoutTz);
} else {
useTz = !withoutTz;
}
return useTz ? 'timestamp with local time zone' : 'timestamp';
},

timestamp: function(without) {
return without ? 'timestamp' : 'timestamp with local time zone';
timestamp: function(withoutTz) {
let useTz;
if (isObject(withoutTz)) {
({ useTz } = withoutTz);
} else {
useTz = !withoutTz;
}
return useTz ? 'timestamp with local time zone' : 'timestamp';
},
});

Expand Down
18 changes: 18 additions & 0 deletions test/unit/schema/oracledb.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,16 @@ describe('OracleDb SchemaBuilder', function() {
expect(tableSql[0].sql).to.equal(
'alter table "users" add "foo" timestamp with local time zone'
);
tableSql = client
.schemaBuilder()
.table('users', function() {
this.dateTime('foo', {useTz: true});
})
.toSQL();
equal(1, tableSql.length);
expect(tableSql[0].sql).to.equal(
'alter table "users" add "foo" timestamp with local time zone'
);
});

it('test adding date time without time zone', function() {
Expand All @@ -681,6 +691,14 @@ describe('OracleDb SchemaBuilder', function() {

equal(1, tableSql.length);
expect(tableSql[0].sql).to.equal('alter table "users" add "foo" timestamp');
tableSql = client
.schemaBuilder()
.table('users', function() {
this.dateTime('foo', {useTz: false});
})
.toSQL();
equal(1, tableSql.length);
expect(tableSql[0].sql).to.equal('alter table "users" add "foo" timestamp');
});

it('test adding time', function() {
Expand Down
6 changes: 4 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1410,9 +1410,11 @@ declare namespace Knex {
): ColumnBuilder;
boolean(columnName: string): ColumnBuilder;
date(columnName: string): ColumnBuilder;
dateTime(columnName: string): ColumnBuilder;
dateTime(columnName: string, options?: {useTz?: boolean, precision?: number}): ColumnBuilder;
time(columnName: string): ColumnBuilder;
timestamp(columnName: string, standard?: boolean): ColumnBuilder;
timestamp(columnName: string, options?: {useTz?: boolean, precision?: number}): ColumnBuilder;
/** @deprecated */
timestamp(columnName: string, withoutTz?: boolean, precision?: number): ColumnBuilder;
timestamps(
useTimestampType?: boolean,
makeDefaultNow?: boolean
Expand Down

0 comments on commit e2e044c

Please sign in to comment.