SQL raw

This guide assumes familiarity with:

sql.raw lets you dynamically build SQL by embedding raw strings:

IMPORTANT

Beware sql.raw does not get escaped and going to be embedded into SQL statement as is

await sql`select * from "users" ${sql.raw("where id = 10")}`
select * from "users" where id = 10;
const listUsers = async (filter: string | undefined) => {
  const whereClause = filter ? sql.raw(` where ${filter}`) : sql.raw("");
  return sql`select * from "users"${whereClause}`;
}

await listUsers(`"id" = 10`);
await listUsers(`"name" = 'Dan'`);
await listUsers();
select * from "users" where "id" = 10;
select * from "users" where "name" = 'Dan';
select * from "users";