Hi everyone,
I have this code:
const query = sql`select * from "collections" c where c."label" ilike '%' || ${label} || '%'`
const rawRows = await query
this works fine. However, I would like to separate the query into a template and then use it in several places. The parameter expansion should still be SQL-safe.
This is "conceptually" what I would like to do, but i somehow can't get it to work.
const QUERY_TEMPLATES = {
GetByLabel = `select * from "collections" c where c."label" ilike '%' || $1 || '%'`
}
// ...
const rows = await sql(QUERY_TEMPLATES.GetByLabel, [param1])
Does anyone know how this is done?