-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
45 lines (37 loc) · 857 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const knex = require('knex')({
client: 'pg',
connection:
{
host: 'localhost',
user: 'postgres',
socketPath: '',
password: '',
database: 'test_timezone',
},
pool: {
afterCreate: (conn, cb) => {
conn.query(`SET timezone = 'UTC'`, err => {
cb(err, conn);
});
}
},
useNullAsDefault: true
});
async function main() {
await knex.schema.dropTableIfExists('counter')
await knex.schema.createTable('counter', table => {
table.increments();
table.integer('amount').notNull();
table
.datetime('createdAt')
.notNullable()
.defaultTo(knex.fn.now());
table
.datetime('updatedAt')
.notNullable()
.defaultTo(knex.fn.now());
});
await knex('counter').returning('id').insert({ amount: 5 });
knex.destroy();
}
main();