@@ -785,7 +785,7 @@ t('Stream returns empty array', async() => {
785785
786786t ( 'Cursor works' , async ( ) => {
787787 const order = [ ]
788- await sql `select 1 as x union select 2 as x` . cursor ( async ( x ) => {
788+ await sql `select 1 as x union select 2 as x` . cursor ( async ( x ) => {
789789 order . push ( x . x + 'a' )
790790 await new Promise ( r => setTimeout ( r , 100 ) )
791791 order . push ( x . x + 'b' )
@@ -795,15 +795,15 @@ t('Cursor works', async() => {
795795
796796t ( 'Cursor custom n works' , async ( ) => {
797797 const order = [ ]
798- await sql `select * from generate_series(1,20)` . cursor ( 10 , async ( x ) => {
798+ await sql `select * from generate_series(1,20)` . cursor ( 10 , async ( x ) => {
799799 order . push ( x . length )
800800 } )
801801 return [ '10,10' , order . join ( ',' ) ]
802802} )
803803
804804t ( 'Cursor cancel works' , async ( ) => {
805805 let result
806- await sql `select * from generate_series(1,10) as x` . cursor ( async ( { x } ) => {
806+ await sql `select * from generate_series(1,10) as x` . cursor ( async ( { x } ) => {
807807 result = x
808808 return sql . END
809809 } )
@@ -812,10 +812,10 @@ t('Cursor cancel works', async() => {
812812
813813t ( 'Cursor throw works' , async ( ) => {
814814 const order = [ ]
815- await sql `select 1 as x union select 2 as x` . cursor ( async ( x ) => {
815+ await sql `select 1 as x union select 2 as x` . cursor ( async ( x ) => {
816816 order . push ( x . x + 'a' )
817817 await new Promise ( r => setTimeout ( r , 100 ) )
818- throw 'watty'
818+ throw new Error ( 'watty' )
819819 } ) . catch ( ( ) => order . push ( 'err' ) )
820820 return [ '1aerr' , order . join ( '' ) ]
821821} )
@@ -965,3 +965,24 @@ t('requests works after single connect_timeout', async() => {
965965t ( 'Postgres errors are of type PostgresError' , async ( ) =>
966966 [ true , ( await sql `bad keyword` . catch ( e => e ) ) instanceof sql . PostgresError ]
967967)
968+
969+ t ( 'Result has columns spec' , async ( ) =>
970+ [ 'x' , ( await sql `select 1 as x` ) . columns [ 0 ] . name ]
971+ )
972+
973+ t ( 'Stream has result as second argument' , async ( ) => {
974+ let x
975+ await sql `select 1 as x` . stream ( ( _ , result ) => x = result )
976+ return [ 'x' , x . columns [ 0 ] . name ]
977+ } )
978+
979+ t ( 'Result as arrays' , async ( ) => {
980+ const sql = postgres ( {
981+ ...options ,
982+ transform : {
983+ row : x => Object . values ( x )
984+ }
985+ } )
986+
987+ return [ '1,2' , ( await sql `select 1 as a, 2 as b` ) [ 0 ] . join ( ',' ) ]
988+ } )
0 commit comments