File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff 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 ( ) {
Original file line number Diff line number Diff 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+
959975t ( 'Cursor cancel works' , async ( ) => {
960976 let result
961977 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