@@ -4,35 +4,36 @@ var connectionString = helper.connectionString();
44var testForTypeCoercion = function ( type ) {
55 helper . pg . connect ( connectionString , function ( err , client ) {
66 assert . isNull ( err )
7- client . query ( "create temp table test_type(col " + type . name + ")" ) ;
7+ client . query ( "create temp table test_type(col " + type . name + ")" , assert . calls ( function ( err , result ) {
8+ assert . isNull ( err ) ;
9+ test ( "Coerces " + type . name , function ( ) {
10+ type . values . forEach ( function ( val ) {
811
9- test ( "Coerces " + type . name , function ( ) {
10- type . values . forEach ( function ( val ) {
12+ var insertQuery = client . query ( 'insert into test_type(col) VALUES($1)' , [ val ] , assert . calls ( function ( err , result ) {
13+ assert . isNull ( err ) ;
14+ } ) ) ;
1115
12- var insertQuery = client . query ( {
13- name : 'insert type test ' + type . name ,
14- text : 'insert into test_type(col) VALUES($1)' ,
15- values : [ val ]
16- } ) ;
16+ var query = client . query ( {
17+ name : 'get type ' + type . name ,
18+ text : 'select col from test_type'
19+ } ) ;
20+ query . on ( 'error' , function ( err ) {
21+ console . log ( err ) ;
22+ throw err ;
23+ } ) ;
1724
18- var query = client . query ( {
19- name : 'get type ' + type . name ,
20- text : 'select col from test_type'
21- } ) ;
25+ assert . emits ( query , 'row' , function ( row ) {
26+ assert . strictEqual ( row . col , val , "expected " + type . name + " of " + val + " but got " + row [ 0 ] ) ;
27+ } , "row should have been called for " + type . name + " of " + val ) ;
2228
23- assert . emits ( query , 'row' , function ( row ) {
24- assert . strictEqual ( row . col , val , "expected " + type . name + " of " + val + " but got " + row [ 0 ] ) ;
29+ client . query ( 'delete from test_type' ) ;
2530 } ) ;
2631
27- client . query ( {
28- name : 'delete values' ,
29- text : 'delete from test_type'
32+ client . query ( 'drop table test_type' , function ( ) {
33+ sink . add ( ) ;
3034 } ) ;
31- sink . add ( ) ;
32- } ) ;
33-
34- client . query ( 'drop table test_type' ) ;
35- } ) ;
35+ } )
36+ } ) ) ;
3637 } )
3738} ;
3839
@@ -82,14 +83,15 @@ var valueCount = 0;
8283types . forEach ( function ( type ) {
8384 valueCount += type . values . length ;
8485} )
85- sink = new helper . Sink ( valueCount , function ( ) {
86+ sink = new helper . Sink ( types . length , function ( ) {
8687 helper . pg . end ( ) ;
8788} )
8889
89- types . forEach ( testForTypeCoercion ) ;
90+ types . forEach ( function ( type ) {
91+ testForTypeCoercion ( type )
92+ } ) ;
9093
9194test ( "timestampz round trip" , function ( ) {
92-
9395 var now = new Date ( ) ;
9496 var client = helper . client ( ) ;
9597 client . on ( 'error' , function ( err ) {
0 commit comments