mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +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
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import assert from 'assert'
|
|
import helper from './helper'
|
|
import QueryStream from '../src'
|
|
|
|
helper('fast reader', function (client) {
|
|
it('works', function (done) {
|
|
const stream = new QueryStream('SELECT * FROM generate_series(0, 200) num', [])
|
|
const query = client.query(stream)
|
|
const result = []
|
|
stream.on('readable', function () {
|
|
let res = stream.read()
|
|
while (res) {
|
|
if (result.length !== 201) {
|
|
assert(res, 'should not return null on evented reader')
|
|
} else {
|
|
// a readable stream will emit a null datum when it finishes being readable
|
|
// https://nodejs.org/api/stream.html#stream_event_readable
|
|
assert.equal(res, null)
|
|
}
|
|
if (res) {
|
|
result.push(res.num)
|
|
}
|
|
res = stream.read()
|
|
}
|
|
})
|
|
stream.on('end', function () {
|
|
const total = result.reduce(function (prev, cur) {
|
|
return prev + cur
|
|
})
|
|
assert.equal(total, 20100)
|
|
done()
|
|
})
|
|
assert.strictEqual(query.read(2), null)
|
|
})
|
|
})
|