Skip to content

Commit

Permalink
fix: add default value now() of gmt_modified and gmt_create (ali-…
Browse files Browse the repository at this point in the history
  • Loading branch information
nodejh authored and fengmk2 committed Aug 7, 2018
1 parent db3524c commit db6d596
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions test/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,23 @@ describe('async.test.js', function() {
});

describe('insert(table, row[s])', function() {
it('should set now() as a default value for `gmt_create` and `gmt_modified`', async function() {
const result = await this.db.insert(table, [{
name: prefix + 'fengmk2-insert00',
email: prefix + 'm@fengmk2-insert.com',
}, {
name: prefix + 'fengmk2-insert01',
email: prefix + 'm@fengmk2-insert.com',
gmt_create: this.db.literals.now,
gmt_modified: this.db.literals.now,
}]);
assert.equal(result.affectedRows, 2);

const result1 = await this.db.get(table, { name: prefix + 'fengmk2-insert00' }, { columns: [ 'gmt_create', 'gmt_modified' ] });
const result2 = await this.db.get(table, { name: prefix + 'fengmk2-insert01' }, { columns: [ 'gmt_create', 'gmt_modified' ] });
assert.deepEqual(result1.gmt_create, result2.gmt_create);
assert.deepEqual(result2.gmt_modified, result2.gmt_modified);
});
it('should insert one row', async function() {
const result = await this.db.insert(table, {
name: prefix + 'fengmk2-insert1',
Expand Down
4 changes: 2 additions & 2 deletions test/rds_init.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE TABLE IF NOT EXISTS `ali-sdk-test-user` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`gmt_modified` datetime NOT NULL COMMENT 'modified time',
`gmt_create` datetime NOT NULL COMMENT 'create time' DEFAULT NOW(),
`gmt_modified` datetime NOT NULL COMMENT 'modified time' DEFAULT NOW(),
`name` varchar(100) NOT NULL COMMENT 'user name',
`email` varchar(400) NOT NULL,
PRIMARY KEY (`id`),
Expand Down

0 comments on commit db6d596

Please sign in to comment.