@@ -250,21 +250,25 @@ function Postgres(url, options) {
250
250
return sql `select pg_notify(${ channel } , ${ '' + payload } )`
251
251
}
252
252
253
- function unsafe ( xs , args , options = { } ) {
253
+ function unsafe ( xs , args ) {
254
+ return query ( { raw : true , simple : ! args } , connection || getConnection ( ) , xs , args || [ ] )
255
+ }
256
+
257
+ function file ( path , args , options ) {
254
258
if ( ! Array . isArray ( args ) ) {
255
- options = args || [ ]
256
- args = [ ]
259
+ options = args || { }
260
+ args = null
257
261
}
258
- return query ( { raw : true , simple : options . simple } , connection || getConnection ( ) , xs , args )
259
- }
260
262
261
- function file ( path ) {
263
+ if ( 'cache' in options === false )
264
+ options . cache = true
265
+
262
266
const file = files [ path ]
267
+ const q = { raw : true , simple : ! args }
263
268
264
- if ( typeof file === 'string' )
265
- return query ( { raw : true , simple : true } , connection || getConnection ( ) , files [ path ] )
269
+ if ( options . cache && typeof file === 'string' )
270
+ return query ( q , connection || getConnection ( ) , file , args || [ ] )
266
271
267
- const q = { raw : true , simple : true }
268
272
const promise = ( file || ( files [ path ] = new Promise ( ( resolve , reject ) => {
269
273
fs . readFile ( path , 'utf8' , ( err , str ) => {
270
274
if ( err )
@@ -273,7 +277,7 @@ function Postgres(url, options) {
273
277
files [ path ] = str
274
278
resolve ( str )
275
279
} )
276
- } ) ) ) . then ( ( str ) => query ( q , connection || getConnection ( ) , str ) )
280
+ } ) ) ) . then ( str => query ( q , connection || getConnection ( ) , str , args || [ ] ) )
277
281
278
282
promise . stream = fn => ( q . stream = fn , promise )
279
283
0 commit comments