-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-update.js
87 lines (69 loc) · 2.49 KB
/
test-update.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const test = require('test')
test.setup()
var common = require('../common')
var assert = require('assert')
describe('update', () => {
it('update - mysql', () => {
const queryOptions = { dialect: 'mysql' };
assert.equal(
common.Update(queryOptions).into('table1').set({ col: 1 }).build(),
"update `table1` set `col` = 1"
)
assert.equal(
common.Update(queryOptions).into('table1').set({ col1: 1, col2: 2 }).build(),
"update `table1` set `col1` = 1, `col2` = 2"
)
assert.equal(
common.Update(queryOptions).into('table1').set({ col1: 1, col2: 2 }).where({ id: 3 }).build(),
"update `table1` set `col1` = 1, `col2` = 2 where `id` = 3"
)
})
it('update - postgresql', () => {
const queryOptions = { dialect: 'postgresql' };
assert.equal(
common.Update(queryOptions).into('table1').set({ col: 1 }).build(),
'update "table1" set "col" = 1'
)
assert.equal(
common.Update(queryOptions).into('table1').set({ col1: 1, col2: 2 }).build(),
'update "table1" set "col1" = 1, "col2" = 2'
)
assert.equal(
common.Update(queryOptions).into('table1').set({ col1: 1, col2: 2 }).where({ id: 3 }).build(),
'update "table1" set "col1" = 1, "col2" = 2 where "id" = 3'
)
})
it('update - sqlite', () => {
const queryOptions = { dialect: 'sqlite' };
assert.equal(
common.Update(queryOptions).into('table1').set({ col: 1 }).build(),
"update `table1` set `col` = 1"
)
assert.equal(
common.Update(queryOptions).into('table1').set({ col1: 1, col2: 2 }).build(),
"update `table1` set `col1` = 1, `col2` = 2"
)
assert.equal(
common.Update(queryOptions).into('table1').set({ col1: 1, col2: 2 }).where({ id: 3 }).build(),
"update `table1` set `col1` = 1, `col2` = 2 where `id` = 3"
)
})
xit('update - mssql', () => {
const queryOptions = { dialect: 'mssql' };
assert.equal(
common.Update(queryOptions).into('table1').set({ col: 1 }).build(),
"update [table1] set [col] = 1;select @@rowcount"
)
assert.equal(
common.Update(queryOptions).into('table1').set({ col1: 1, col2: 2 }).build(),
"update [table1] set [col1] = 1, [col2] = 2;select @@rowcount"
)
assert.equal(
common.Update(queryOptions).into('table1').set({ col1: 1, col2: 2 }).where({ id: 3 }).build(),
"update [table1] set [col1] = 1, [col2] = 2 where [id] = 3;select @@rowcount"
)
})
})
if (require.main === module) {
test.run(console.DEBUG)
}