Skip to content

Commit

Permalink
Make stream promise resolve with correct result
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Dec 29, 2019
1 parent 748f198 commit 730df2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ function Connection(options = {}) {
function onready(err) {
err
? (backend.query ? backend.query.reject(err) : error(err))
: (backend.query && backend.query.resolve(backend.query.stream
? backend.query.result.count
: (backend.query.results || backend.query.result)))
: (backend.query && backend.query.resolve(backend.query.results || backend.query.result))

backend.query = backend.error = null
timeout && queries.length === 0 && idle()
Expand Down
10 changes: 10 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,16 @@ t('bytea serializes and parses', async() => {
return [0, Buffer.compare(buf, (await sql`select x from test`)[0].x)]
})

t('Stream works', async() => {
let result
await sql`select 1 as x`.stream(({ x }) => result = x)
return [1, result]
})

t('Stream returns empty array', async() => {
return [0, (await sql`select 1 as x`.stream(x => {})).length]
})

t('Transform row', async() => {
const sql = postgres({
...options,
Expand Down

0 comments on commit 730df2c

Please sign in to comment.