Skip to content

Commit a10a151

Browse files
committed
Add tests
1 parent 12c6994 commit a10a151

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

packages/pg-query-stream/src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ class QueryStream extends Readable implements Submittable {
2727

2828
super({ objectMode: true, autoDestroy: true, highWaterMark: batchSize || highWaterMark })
2929
this.cursor = new Cursor(text, values, config)
30-
this.cursor.on('end', (result) => {
31-
this.callback && this.callback(null, result)
32-
}).on('error', (err) => {
33-
this.callback && this.callback(err)
34-
})
30+
this.cursor
31+
.on('end', (result) => {
32+
this.callback && this.callback(null, result)
33+
})
34+
.on('error', (err) => {
35+
this.callback && this.callback(err)
36+
})
3537

3638
// delegate Submittable callbacks to cursor
3739
this.handleRowDescription = this.cursor.handleRowDescription.bind(this.cursor)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import assert from 'assert'
2+
import { Pool } from 'pg'
3+
import QueryStream from '../src'
4+
5+
describe('pool', function () {
6+
it('works', async function () {
7+
const pool = new Pool()
8+
const query = new QueryStream('SELECT * FROM generate_series(0, 10) num', [])
9+
const q = pool.query(query)
10+
console.log(q) // Promise { <pending>, ...
11+
query.on('data', (row) => {
12+
// just consume the whole stream
13+
})
14+
await q //!
15+
query.on('end', () => {
16+
pool.end()
17+
})
18+
})
19+
})

0 commit comments

Comments
 (0)