forked from brianc/node-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassing-options.ts
38 lines (36 loc) · 1.09 KB
/
passing-options.ts
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
import assert from 'assert'
import helper from './helper'
import QueryStream from '../src'
helper('passing options', function (client) {
it('passes row mode array', function (done) {
const stream = new QueryStream('SELECT * FROM generate_series(0, 10) num', [], { rowMode: 'array' })
const query = client.query(stream)
const result = []
query.on('data', (datum) => {
result.push(datum)
})
query.on('end', () => {
const expected = new Array(11).fill(0).map((_, i) => [i])
assert.deepEqual(result, expected)
done()
})
})
it('passes custom types', function (done) {
const types = {
getTypeParser: () => (string) => string,
}
const stream = new QueryStream('SELECT * FROM generate_series(0, 10) num', [], { types })
const query = client.query(stream)
const result = []
query.on('data', (datum) => {
result.push(datum)
})
query.on('end', () => {
const expected = new Array(11).fill(0).map((_, i) => ({
num: i.toString(),
}))
assert.deepEqual(result, expected)
done()
})
})
})