Skip to content

Commit cea5f73

Browse files
committed
Include missing last set in cursor - fixes porsager#150 porsager#81
1 parent 2e3652b commit cea5f73

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/connection.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ function Connection(options = {}) {
6161
error
6262
})
6363

64-
function onsuspended(x) {
64+
function onsuspended(x, done) {
6565
new Promise(r => r(backend.query.cursor(
6666
backend.query.cursor.rows === 1 ? x[0] : x
6767
))).then(x => {
68-
x === END
68+
x === END || done
6969
? socket.write(frontend.Close())
7070
: socket.write(frontend.Execute(backend.query.cursor.rows))
7171
}).catch(err => {
@@ -75,7 +75,7 @@ function Connection(options = {}) {
7575
}
7676

7777
function oncomplete() {
78-
backend.query.cursor && socket.write(frontend.Close())
78+
backend.query.cursor && onsuspended(backend.query.result, true)
7979
}
8080

8181
function onparse() {

tests/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,22 @@ t('Cursor custom n works', async() => {
956956
return ['10,10', order.join(',')]
957957
})
958958

959+
ot('Cursor custom with rest n works', async() => {
960+
const order = []
961+
await sql`select * from generate_series(1,20)`.cursor(11, async(x) => {
962+
order.push(x.length)
963+
})
964+
return ['11,9', order.join(',')]
965+
})
966+
967+
ot('Cursor custom with less results than batch size works', async() => {
968+
const order = []
969+
await sql`select * from generate_series(1,20)`.cursor(21, async(x) => {
970+
order.push(x.length)
971+
})
972+
return ['11,9', order.join(',')]
973+
})
974+
959975
t('Cursor cancel works', async() => {
960976
let result
961977
await sql`select * from generate_series(1,10) as x`.cursor(async({ x }) => {

0 commit comments

Comments
 (0)