@@ -135,12 +135,10 @@ export default function Postgres(url, options) {
135
135
}
136
136
}
137
137
138
- function query ( { raw , simple } , connection , xs , args ) {
139
- if ( ! raw && ( ! Array . isArray ( xs ) || ! Array . isArray ( xs . raw ) ) )
138
+ function query ( query , connection , xs , args ) {
139
+ if ( ! query . raw && ( ! Array . isArray ( xs ) || ! Array . isArray ( xs . raw ) ) )
140
140
throw errors . generic ( { message : 'Query not called as a tagged template literal' , code : 'NOT_TAGGED_CALL' } )
141
141
142
- const query = { raw, simple }
143
-
144
142
const promise = new Promise ( ( resolve , reject ) => {
145
143
query . resolve = resolve
146
144
query . reject = reject
@@ -291,15 +289,18 @@ export default function Postgres(url, options) {
291
289
if ( typeof file === 'string' )
292
290
return query ( { raw : true , simple : true } , connection || getConnection ( ) , files [ path ] )
293
291
294
- const promise = ( file || new Promise ( ( resolve , reject ) => fs . readFile ( path , 'utf8' , ( err , str ) => {
295
- if ( err )
296
- return reject ( err )
292
+ const q = { raw : true , simple : true }
293
+ const promise = ( file || ( files [ path ] = new Promise ( ( resolve , reject ) => {
294
+ fs . readFile ( path , 'utf8' , ( err , str ) => {
295
+ if ( err )
296
+ return reject ( err )
297
+
298
+ files [ path ] = str
299
+ resolve ( str )
300
+ } )
301
+ } ) ) ) . then ( ( str ) => query ( q , connection || getConnection ( ) , str ) )
297
302
298
- files [ path ] = str
299
- const q = query ( { raw : true , simple : true } , connection || getConnection ( ) , files [ path ] )
300
- promise . stream = q . stream
301
- resolve ( q )
302
- } ) ) )
303
+ promise . stream = fn => ( q . stream = fn , promise )
303
304
304
305
return promise
305
306
}
0 commit comments