1
+ 'use strict'
2
+
1
3
var pg = require ( 'pg' )
2
- , QueryStream = require ( 'pg-query-stream' )
3
- , inherits = require ( 'inherits' )
4
+ var QueryStream = require ( 'pg-query-stream' )
5
+ var inherits = require ( 'inherits' )
4
6
5
7
var adapter = exports
6
8
7
9
adapter . name = 'postgres'
8
10
9
11
adapter . createQuery = function ( text , params , callback ) {
10
- if ( typeof text === 'string' )
12
+ if ( typeof text === 'string' ) {
11
13
return new PostgresQuery ( text , params , callback )
14
+ }
12
15
return text
13
16
}
14
17
@@ -29,19 +32,20 @@ PostgresConnection.prototype.adapter = adapter
29
32
PostgresConnection . prototype . query = function ( text , params , callback ) {
30
33
var query = this . adapter . createQuery ( text , params , callback )
31
34
this . emit ( 'query' , query )
32
- return pg . Client . prototype . query . call ( this , query ) ;
35
+ return pg . Client . prototype . query . call ( this , query )
33
36
}
34
37
35
38
inherits ( PostgresQuery , QueryStream )
36
39
function PostgresQuery ( text , params , callback ) {
37
- if ( typeof params == 'function' ) {
40
+ if ( typeof params === 'function' ) {
38
41
callback = params
39
42
params = [ ]
40
43
}
41
- if ( ! params ) params = [ ] ;
44
+ if ( ! params ) params = [ ]
42
45
this . constructor . super_ . call ( this , text , params )
43
46
this . super_ = this . constructor . super_ . prototype
44
- if ( this . callback = callback ) {
47
+ if ( callback ) {
48
+ this . callback = callback
45
49
var errored = false
46
50
this
47
51
. on ( 'error' , function ( err ) {
@@ -54,6 +58,8 @@ function PostgresQuery (text, params, callback) {
54
58
. on ( 'end' , function ( ) {
55
59
if ( ! errored ) this . callback ( null , this . _result )
56
60
} )
61
+ } else {
62
+ this . callback = null
57
63
}
58
64
}
59
65
0 commit comments