Skip to content

Commit

Permalink
UpdatableTimeColumnDefinition: Add .defaultCurrentTimestamp() method
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoltman committed Dec 12, 2016
1 parent 5021ba5 commit 949d72f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,7 @@ Compatible types:

Methods:

+ `defaultCurrentTimestamp()` - Adds the `DEFAULT CURRENT_TIMESTAMP` attribute
+ `onUpdateCurrentTimestamp()` - Adds the `ON UPDATE CURRENT_TIMESTAMP` attribute

Compatible types:
Expand Down
1 change: 1 addition & 0 deletions jsdoc2md/README.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ Compatible types:

Methods:

+ `defaultCurrentTimestamp()` - Adds the `DEFAULT CURRENT_TIMESTAMP` attribute
+ `onUpdateCurrentTimestamp()` - Adds the `ON UPDATE CURRENT_TIMESTAMP` attribute

Compatible types:
Expand Down
2 changes: 1 addition & 1 deletion lib/ColumnDefinitions/ColumnDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const util = require('util');
const warnDeprecatedDefault = util.deprecate(
() => { /* no-op */ },
'Calling `.default(\'CURRENT_TIMESTAMP\')` has been deprecated because `.default()` will always escape values ' +
'starting in version 0.5.0. Please use `.defaultRaw(\'CURRENT_TIMESTAMP\')` instead.'
'starting in version 0.6.0. Please use `.defaultCurrentTimestamp()` instead.'
);

class ColumnDefinition {
Expand Down
4 changes: 4 additions & 0 deletions lib/ColumnDefinitions/UpdatableTimeColumnDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class UpdatableTimeColumnDefinition extends ColumnDefinition {
this._onUpdateCurrentTimestamp = false;
}

defaultCurrentTimestamp() {
return this.defaultRaw('CURRENT_TIMESTAMP');
}

onUpdateCurrentTimestamp() {
this._onUpdateCurrentTimestamp = true;
return this;
Expand Down
8 changes: 8 additions & 0 deletions test/unit/ColumnDefinitions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,14 @@ describe('ColumnDefinitions', () => {

describe('updatable time data types', () => {

it('should provide the defaultCurrentTimestamp() method', () => {
ColumnDefinitions.datetime().defaultCurrentTimestamp().$toSQL()
.should.equal('datetime DEFAULT CURRENT_TIMESTAMP');

ColumnDefinitions.timestamp().defaultCurrentTimestamp().$toSQL()
.should.equal('timestamp DEFAULT CURRENT_TIMESTAMP');
});

it('should provide the onUpdateCurrentTimestamp() method', () => {
var cd;

Expand Down

0 comments on commit 949d72f

Please sign in to comment.