Skip to content

Commit e4f12a4

Browse files
committed
Fix params usage for file() call without options
1 parent 2f277bc commit e4f12a4

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function Postgres(url, options) {
254254
return query({ raw: true, simple: !args, dynamic: true }, connection || getConnection(), xs, args || [])
255255
}
256256

257-
function file(path, args, options) {
257+
function file(path, args, options = {}) {
258258
if (!Array.isArray(args)) {
259259
options = args || {}
260260
args = null

tests/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,14 @@ t('sql file cached', async() => {
353353
return [1, (await sql.file(path.join(__dirname, 'select.sql')))[0].x]
354354
})
355355

356+
t('Parameters in file', async() => {
357+
const result = await sql.file(
358+
path.join(__dirname, 'select-param.sql'),
359+
['hello']
360+
)
361+
return ['hello', result[0].x]
362+
})
363+
356364
t('Connection ended promise', async() => {
357365
const sql = postgres(options)
358366

tests/select-param.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select $1 as x

0 commit comments

Comments
 (0)