@@ -37,7 +37,7 @@ export default function Postgres(url, options) {
37
37
, typeArrayMap = { }
38
38
39
39
function postgres ( xs , ...args ) {
40
- return query ( false , getConnection ( ) , xs , args )
40
+ return query ( { } , getConnection ( ) , xs , args )
41
41
}
42
42
43
43
Object . assign ( postgres , {
@@ -93,7 +93,7 @@ export default function Postgres(url, options) {
93
93
} , connection )
94
94
} )
95
95
96
- query ( true , connection , begin || savepoint )
96
+ query ( { raw : true } , connection , begin || savepoint )
97
97
. then ( ( ) => {
98
98
const result = fn ( scoped )
99
99
return Array . isArray ( result )
@@ -106,7 +106,7 @@ export default function Postgres(url, options) {
106
106
: resolve ( x )
107
107
)
108
108
. catch ( ( err ) => {
109
- query ( true , connection ,
109
+ query ( { raw : true } , connection ,
110
110
begin
111
111
? 'rollback'
112
112
: 'rollback to ' + savepoint
@@ -119,7 +119,7 @@ export default function Postgres(url, options) {
119
119
} )
120
120
121
121
function scoped ( xs , ...args ) {
122
- return query ( false , connection , xs , args ) . catch ( reject )
122
+ return query ( { } , connection , xs , args ) . catch ( reject )
123
123
}
124
124
}
125
125
@@ -133,11 +133,11 @@ export default function Postgres(url, options) {
133
133
}
134
134
}
135
135
136
- function query ( raw , connection , xs , args ) {
136
+ function query ( { raw, simple } , connection , xs , args ) {
137
137
if ( ! raw && ( ! Array . isArray ( xs ) || ! Array . isArray ( xs . raw ) ) )
138
138
throw errors . generic ( { message : 'Query not called as a tagged template literal' , code : 'NOT_TAGGED_CALL' } )
139
139
140
- const query = { raw }
140
+ const query = { raw, simple }
141
141
142
142
const promise = new Promise ( ( resolve , reject ) => {
143
143
query . resolve = resolve
@@ -184,7 +184,7 @@ export default function Postgres(url, options) {
184
184
const container = fn ( scoped )
185
185
function scoped ( xs , ...args ) {
186
186
queries ++
187
- const promise = query ( false , connection , xs , args )
187
+ const promise = query ( { } , connection , xs , args )
188
188
promise . then ( finished , finished )
189
189
return promise
190
190
}
@@ -255,14 +255,26 @@ export default function Postgres(url, options) {
255
255
256
256
function addTypes ( sql , connection ) {
257
257
Object . assign ( sql , {
258
- notify : ( channel , payload ) => sql `select pg_notify( ${ channel } , ${ '' + payload } )` ,
259
- unsafe : ( xs , args ) => query ( true , connection || getConnection ( ) , xs , args ) ,
258
+ notify,
259
+ unsafe,
260
260
array,
261
261
rows,
262
262
row,
263
263
json
264
264
} )
265
265
266
+ function notify ( channel , payload ) {
267
+ return sql `select pg_notify(${ channel } , ${ '' + payload } )`
268
+ }
269
+
270
+ function unsafe ( xs , args , options = { } ) {
271
+ if ( ! Array . isArray ( args ) ) {
272
+ options = args || [ ]
273
+ args = [ ]
274
+ }
275
+ return query ( { raw : true , simple : options . simple } , connection || getConnection ( ) , xs , args )
276
+ }
277
+
266
278
options . types && Object . entries ( options . types ) . forEach ( ( [ name , type ] ) => {
267
279
if ( name in sql )
268
280
throw errors . generic ( { message : name + ' is a reserved method name' , code : 'RESERVED_METHOD_NAME' } )
@@ -279,7 +291,7 @@ export default function Postgres(url, options) {
279
291
? listeners [ x ] . push ( fn )
280
292
: ( listeners [ x ] = [ fn ] )
281
293
282
- return query ( true , getListener ( ) , 'listen "' + x + '"' ) . then ( ( ) => x )
294
+ return query ( { raw : true } , getListener ( ) , 'listen "' + x + '"' ) . then ( ( ) => x )
283
295
}
284
296
285
297
function getListener ( ) {
0 commit comments