Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add default value now() of gmt_modified and gmt_create #56

Merged
merged 3 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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