Skip to content

Commit 7706ccb

Browse files
author
alxndrsn
committed
Add test; use string for queryMode
1 parent 1b4518f commit 7706ccb

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

docs/pages/apis/client.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ type QueryConfig {
7676
// custom type parsers just for this query result
7777
types?: Types;
7878

79-
// force extended query usage - prevents multiple statements in a
80-
// single query
81-
forcePreparation?: boolean;
79+
// TODO: document
80+
queryMode?: string;
8281
}
8382
```
8483

packages/pg/lib/native/query.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var NativeQuery = (module.exports = function (config, values, callback) {
1010
this.text = config.text
1111
this.values = config.values
1212
this.name = config.name
13-
this.forcePreparation = config.forcePreparation
13+
this.queryMode = config.forcePreparation
1414
this.callback = config.callback
1515
this.state = 'new'
1616
this._arrayMode = config.rowMode === 'array'
@@ -160,7 +160,7 @@ NativeQuery.prototype.submit = function (client) {
160160
}
161161
var vals = this.values.map(utils.prepareValue)
162162
client.native.query(this.text, vals, after)
163-
} else if (this.forcePreparation) {
163+
} else if (this.queryMode === 'extended') {
164164
client.native.query(this.text, [], after)
165165
} else {
166166
client.native.query(this.text, after)

packages/pg/lib/query.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Query extends EventEmitter {
1616
this.rows = config.rows
1717
this.types = config.types
1818
this.name = config.name
19-
this.forcePreparation = config.forcePreparation
19+
this.queryMode = config.queryMode
2020
this.binary = config.binary
2121
// use unique portal name each time
2222
this.portal = config.portal || ''
@@ -33,8 +33,7 @@ class Query extends EventEmitter {
3333
}
3434

3535
requiresPreparation() {
36-
// preparation has been requested
37-
if (this.forcePreparation) {
36+
if (this.queryMode === 'extended') {
3837
return true
3938
}
4039

packages/pg/test/integration/client/multiple-results-tests.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ suite.test(
2525
})
2626
)
2727

28+
suite.test(
29+
'throws if queryMode set to "extended"',
30+
co.wrap(function* () {
31+
const client = new helper.Client()
32+
yield client.connect()
33+
34+
// TODO should be text or sql?
35+
try {
36+
const results = yield client.query({
37+
text: `SELECT 'foo'::text as name; SELECT 'bar'::text as baz`,
38+
queryMode: 'extended',
39+
})
40+
assert.fail('Should have thrown');
41+
} catch(err) {
42+
if(err instanceof assert.AssertionError) throw err;
43+
44+
assert.equal(err.severity, 'ERROR');
45+
assert.equal(err.code, '42601');
46+
assert.equal(err.message, 'cannot insert multiple commands into a prepared statement');
47+
}
48+
49+
return client.end()
50+
})
51+
)
52+
2853
suite.test(
2954
'multiple selects work',
3055
co.wrap(function* () {

0 commit comments

Comments
 (0)