@@ -785,7 +785,7 @@ t('Stream returns empty array', async() => {
785
785
786
786
t ( 'Cursor works' , async ( ) => {
787
787
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 ) => {
789
789
order . push ( x . x + 'a' )
790
790
await new Promise ( r => setTimeout ( r , 100 ) )
791
791
order . push ( x . x + 'b' )
@@ -795,15 +795,15 @@ t('Cursor works', async() => {
795
795
796
796
t ( 'Cursor custom n works' , async ( ) => {
797
797
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 ) => {
799
799
order . push ( x . length )
800
800
} )
801
801
return [ '10,10' , order . join ( ',' ) ]
802
802
} )
803
803
804
804
t ( 'Cursor cancel works' , async ( ) => {
805
805
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 } ) => {
807
807
result = x
808
808
return sql . END
809
809
} )
@@ -812,10 +812,10 @@ t('Cursor cancel works', async() => {
812
812
813
813
t ( 'Cursor throw works' , async ( ) => {
814
814
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 ) => {
816
816
order . push ( x . x + 'a' )
817
817
await new Promise ( r => setTimeout ( r , 100 ) )
818
- throw 'watty'
818
+ throw new Error ( 'watty' )
819
819
} ) . catch ( ( ) => order . push ( 'err' ) )
820
820
return [ '1aerr' , order . join ( '' ) ]
821
821
} )
@@ -965,3 +965,24 @@ t('requests works after single connect_timeout', async() => {
965
965
t ( 'Postgres errors are of type PostgresError' , async ( ) =>
966
966
[ true , ( await sql `bad keyword` . catch ( e => e ) ) instanceof sql . PostgresError ]
967
967
)
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