-
Adds
sql.concat
for concatenating an array of SQLs.
This could be useful for generating a series ofAND
s orORs
:var ranges = [[10, 15], [25, 30], [40, 45]] sql` SELECT * FROM models WHERE age = 0 ${sql.concat(ranges.map(([a, b]) => sql` OR age BETWEEN ${a} AND ${b}`))} `
-
Adds
sql.in
for easier use inIN
queries.Given an empty array,
sql.in
returns(NULL)
. This prevents a SQL syntax error due to the empty tuple (()
) you'd get withsql.tuple
while still causing theIN
query to not match anything. Note however that aNOT IN (NULL)
query will always fail to match. See the README on how to handle that.
-
Interpolates arrays always as single values (as opposed to comma separated list) to be more consistent in face of dynamic input.
To now generate
id IN (1, 2, 3)
queries, usesql.tuple
:sql`SELECT * FROM models WHERE id IN ${sql.tuple(ids)} AND age > ${age}`
To generate
tags @> ARRAY[${tags}]
queries, usesql.csv
:sql`SELECT * FROM cars WHERE tags @> ARRAY[${sql.csv(tags)}]`
While the prior comma separated default was convenient for the two cases above, it interfered with
UPDATE models SET tags = ${tags}
. It may also have generated invalid SQL if you didn't expect some value to be an array. It wouldn't have caused a security issue, but invalid SQL wasn't great either. -
Adds support for calling
Sql.prototype.toString
with other placeholder formats. -
Fixes PostgreSQL support by using
$
placeholders, not?
s.
- Things could sqlate quickly.