Skip to content

Commit deaef0a

Browse files
committed
feat: use stable query syntax
Prevents issues described in https://github.com/gajus/slonik#slonik-query-building-sql-array. The resulting query is always of predictable length. Related to: * gajus/slonik#54
1 parent 4d41249 commit deaef0a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/routines/getByIds.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ export default async (
2929
let rows = [];
3030

3131
if (ids.length > 0) {
32+
const idType = typeof ids[0] === 'number' ? 'int4' : 'text';
33+
3234
rows = await connection.any(sql`
3335
SELECT ${sql.raw(identifiers)}
3436
FROM ${sql.identifier([tableName])}
35-
WHERE ${sql.identifier([idName])} IN (${sql.valueList(ids)})
37+
WHERE ${sql.identifier([idName])} = ANY(${sql.array(ids, idType)})
3638
`);
3739
}
3840

0 commit comments

Comments
 (0)