-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathprepared-statement-tests.js
155 lines (133 loc) · 3.57 KB
/
prepared-statement-tests.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'use strict'
var helper = require('./test-helper')
var Query = require('../../../lib/query')
var client = helper.client()
var con = client.connection
var parseArg = null
con.parse = function (arg) {
parseArg = arg
process.nextTick(function () {
con.emit('parseComplete')
})
}
var bindArg = null
con.bind = function (arg) {
bindArg = arg
process.nextTick(function () {
con.emit('bindComplete')
})
}
var executeArg = null
con.execute = function (arg) {
executeArg = arg
process.nextTick(function () {
con.emit('rowData', { fields: [] })
con.emit('commandComplete', { text: '' })
})
}
var describeArg = null
con.describe = function (arg) {
describeArg = arg
process.nextTick(function () {
con.emit('rowDescription', { fields: [] })
})
}
var syncCalled = false
con.flush = function () {
}
con.sync = function () {
syncCalled = true
process.nextTick(function () {
con.emit('readyForQuery')
})
}
test('bound command', function () {
test('simple, unnamed bound command', function () {
assert.ok(client.connection.emit('readyForQuery'))
var query = client.query(new Query({
text: 'select * from X where name = $1',
values: ['hi']
}))
assert.emits(query, 'end', function () {
test('parse argument', function () {
assert.equal(parseArg.name, null)
assert.equal(parseArg.text, 'select * from X where name = $1')
assert.equal(parseArg.types, null)
})
test('bind argument', function () {
assert.equal(bindArg.statement, null)
assert.equal(bindArg.portal, '')
assert.lengthIs(bindArg.values, 1)
assert.equal(bindArg.values[0], 'hi')
})
test('describe argument', function () {
assert.equal(describeArg.type, 'P')
assert.equal(describeArg.name, '')
})
test('execute argument', function () {
assert.equal(executeArg.portal, '')
assert.equal(executeArg.rows, null)
})
test('sync called', function () {
assert.ok(syncCalled)
})
})
})
})
var portalClient = helper.client()
var portalCon = portalClient.connection
var portalParseArg = null
portalCon.parse = function (arg) {
portalParseArg = arg
process.nextTick(function () {
portalCon.emit('parseComplete')
})
}
var portalBindArg = null
portalCon.bind = function (arg) {
portalBindArg = arg
process.nextTick(function () {
portalCon.emit('bindComplete')
})
}
var portalExecuteArg = null
portalCon.execute = function (arg) {
portalExecuteArg = arg
process.nextTick(function () {
portalCon.emit('rowData', { fields: [] })
portalCon.emit('commandComplete', { text: '' })
})
}
var portalDescribeArg = null
portalCon.describe = function (arg) {
portalDescribeArg = arg
process.nextTick(function () {
portalCon.emit('rowDescription', { fields: [] })
})
}
portalCon.flush = function () {
}
portalCon.sync = function () {
process.nextTick(function () {
portalCon.emit('readyForQuery')
})
}
test('prepared statement with explicit portal', function () {
assert.ok(portalClient.connection.emit('readyForQuery'))
var query = portalClient.query(new Query({
text: 'select * from X where name = $1',
portal: 'myportal',
values: ['hi']
}))
assert.emits(query, 'end', function () {
test('bind argument', function () {
assert.equal(portalBindArg.portal, 'myportal')
})
test('describe argument', function () {
assert.equal(portalDescribeArg.name, 'myportal')
})
test('execute argument', function () {
assert.equal(portalExecuteArg.portal, 'myportal')
})
})
})