Skip to content

Commit f36c518

Browse files
committed
binding fix
1 parent 59516f9 commit f36c518

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,26 @@ export default function connect(settings) {
168168
return row;
169169
}
170170

171-
async function raw(sql, options = {}) {
172-
const dbApi = options.dbApi || knex;
173-
const res = await dbApi.raw(sql, options);
171+
async function raw(sql, bindingsOrOptions = {}, options = {}) {
172+
// Support two call shapes:
173+
// raw(sql) — no bindings
174+
// raw(sql, bindings) — array or object bindings (Knex style)
175+
// raw(sql, bindings, options) — bindings + options.dbApi
176+
// raw(sql, { bindings, dbApi }) — options object with bindings key
177+
let bindings;
178+
let opts;
179+
if (Array.isArray(bindingsOrOptions)) {
180+
bindings = bindingsOrOptions;
181+
opts = options;
182+
} else if (bindingsOrOptions && typeof bindingsOrOptions === 'object' && 'bindings' in bindingsOrOptions) {
183+
bindings = bindingsOrOptions.bindings;
184+
opts = bindingsOrOptions;
185+
} else {
186+
bindings = undefined;
187+
opts = bindingsOrOptions;
188+
}
189+
const dbApi = opts.dbApi || knex;
190+
const res = bindings !== undefined ? await dbApi.raw(sql, bindings) : await dbApi.raw(sql);
174191
return res.rows || res;
175192
}
176193

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "breadfruit",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"description": "Boilerplate SQL query helpers for Node.js using Knex",
55
"type": "module",
66
"main": "./index.js",

0 commit comments

Comments
 (0)