@@ -26,20 +26,22 @@ test('connects', function() {
2626 } )
2727 } )
2828} )
29-
30- test ( 'multiple results' , function ( ) {
29+ var setupClient = function ( ) {
3130 var client = new Client ( conString ) ;
3231 client . connect ( ) ;
32+ client . query ( "CREATE TEMP TABLE boom(name varchar(10))" ) ;
33+ client . query ( "INSERT INTO boom(name) VALUES('Aaron')" ) ;
34+ client . query ( "INSERT INTO boom(name) VALUES('Brian')" ) ;
35+ return client ;
36+ }
37+ test ( 'multiple results' , function ( ) {
3338 test ( 'queued queries' , function ( ) {
34- client . query ( "CREATE TEMP TABLE boom(name varchar(10))" ) ;
35- client . query ( "INSERT INTO boom(name) VALUES('Aaron')" ) ;
36- client . query ( "INSERT INTO boom(name) VALUES('Brian')" ) ;
39+ var client = setupClient ( ) ;
3740 var q = client . query ( "SELECT * from BOOM" ) ;
3841 assert . emits ( q , 'row' , function ( row ) {
3942 assert . equal ( row . name , 'Aaron' ) ;
4043 assert . emits ( q , 'row' , function ( row ) {
4144 assert . equal ( row . name , "Brian" ) ;
42-
4345 } )
4446 } )
4547 assert . emits ( q , 'end' , function ( ) {
@@ -55,3 +57,31 @@ test('multiple results', function() {
5557 } )
5658 } )
5759} )
60+
61+ test ( 'parameterized queries' , function ( ) {
62+ test ( 'with a single string param' , function ( ) {
63+ var client = setupClient ( ) ;
64+ var q = client . query ( "SELECT name FROM boom WHERE name = $1" , [ 'Brian' ] ) ;
65+ assert . emits ( q , 'row' , function ( row ) {
66+ assert . equal ( row . name , 'Brian' )
67+ } )
68+ assert . emits ( q , 'end' , function ( ) {
69+ client . end ( ) ;
70+ } ) ;
71+ } )
72+ test ( 'with object config for query' , function ( ) {
73+ var client = setupClient ( ) ;
74+ var q = client . query ( {
75+ text : "SELECT name FROM boom WHERE name = $1" ,
76+ values : [ 'Brian' ]
77+ } ) ;
78+ assert . emits ( q , 'row' , function ( row ) {
79+ assert . equal ( row . name , 'Brian' ) ;
80+ } )
81+ assert . emits ( q , 'end' , function ( ) {
82+ client . end ( ) ;
83+ } )
84+ } )
85+
86+ } )
87+
0 commit comments