diff --git a/test/async.js b/test/async.js index cd0d9d1..fbe75e0 100644 --- a/test/async.js +++ b/test/async.js @@ -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', diff --git a/test/rds_init.sql b/test/rds_init.sql index 7d9b7fa..de92688 100644 --- a/test/rds_init.sql +++ b/test/rds_init.sql @@ -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`),