Skip to content

Commit db6d596

Browse files
nodejhfengmk2
authored andcommitted
fix: add default value now() of gmt_modified and gmt_create (ali-sdk#56)
1 parent db3524c commit db6d596

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

test/async.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,23 @@ describe('async.test.js', function() {
543543
});
544544

545545
describe('insert(table, row[s])', function() {
546+
it('should set now() as a default value for `gmt_create` and `gmt_modified`', async function() {
547+
const result = await this.db.insert(table, [{
548+
name: prefix + 'fengmk2-insert00',
549+
email: prefix + 'm@fengmk2-insert.com',
550+
}, {
551+
name: prefix + 'fengmk2-insert01',
552+
email: prefix + 'm@fengmk2-insert.com',
553+
gmt_create: this.db.literals.now,
554+
gmt_modified: this.db.literals.now,
555+
}]);
556+
assert.equal(result.affectedRows, 2);
557+
558+
const result1 = await this.db.get(table, { name: prefix + 'fengmk2-insert00' }, { columns: [ 'gmt_create', 'gmt_modified' ] });
559+
const result2 = await this.db.get(table, { name: prefix + 'fengmk2-insert01' }, { columns: [ 'gmt_create', 'gmt_modified' ] });
560+
assert.deepEqual(result1.gmt_create, result2.gmt_create);
561+
assert.deepEqual(result2.gmt_modified, result2.gmt_modified);
562+
});
546563
it('should insert one row', async function() {
547564
const result = await this.db.insert(table, {
548565
name: prefix + 'fengmk2-insert1',

test/rds_init.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CREATE TABLE IF NOT EXISTS `ali-sdk-test-user` (
22
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
3-
`gmt_create` datetime NOT NULL COMMENT 'create time',
4-
`gmt_modified` datetime NOT NULL COMMENT 'modified time',
3+
`gmt_create` datetime NOT NULL COMMENT 'create time' DEFAULT NOW(),
4+
`gmt_modified` datetime NOT NULL COMMENT 'modified time' DEFAULT NOW(),
55
`name` varchar(100) NOT NULL COMMENT 'user name',
66
`email` varchar(400) NOT NULL,
77
PRIMARY KEY (`id`),

0 commit comments

Comments
 (0)