File tree 2 files changed +19
-3
lines changed
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -61,11 +61,11 @@ function Connection(options = {}) {
61
61
error
62
62
} )
63
63
64
- function onsuspended ( x ) {
64
+ function onsuspended ( x , done ) {
65
65
new Promise ( r => r ( backend . query . cursor (
66
66
backend . query . cursor . rows === 1 ? x [ 0 ] : x
67
67
) ) ) . then ( x => {
68
- x === END
68
+ x === END || done
69
69
? socket . write ( frontend . Close ( ) )
70
70
: socket . write ( frontend . Execute ( backend . query . cursor . rows ) )
71
71
} ) . catch ( err => {
@@ -75,7 +75,7 @@ function Connection(options = {}) {
75
75
}
76
76
77
77
function oncomplete ( ) {
78
- backend . query . cursor && socket . write ( frontend . Close ( ) )
78
+ backend . query . cursor && onsuspended ( backend . query . result , true )
79
79
}
80
80
81
81
function onparse ( ) {
Original file line number Diff line number Diff line change @@ -956,6 +956,22 @@ t('Cursor custom n works', async() => {
956
956
return [ '10,10' , order . join ( ',' ) ]
957
957
} )
958
958
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
+
959
975
t ( 'Cursor cancel works' , async ( ) => {
960
976
let result
961
977
await sql `select * from generate_series(1,10) as x` . cursor ( async ( { x } ) => {
You can’t perform that action at this time.
0 commit comments