mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
* feat(): start converting pg-query stream * feat(): solution project, initial version of typescript-pg-query stream * chore(): mocha with typescript * fix(): eslint ignore query stream dist * refactor(pg-query-stream): convert test to ts * chore(): fixed type errors * chore(): fix helper usage * chore(): use ts-node compatibile with node v8 * fix(): addd es extension * chore(): remove emitClose and added compilation for async iterators * chore(): condition for asyc iteration test * chore(): rename class to match ts-defs * chore(): tests to import from src instead of dist * chore(): remove prettier from peer deps: * chore(): update lock file
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
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()
|
|
})
|
|
})
|
|
})
|