Waddler SQL identifier
This guide assumes familiarity with:
sql.identifier
lets you conveniently pass identifiers to SQL query with automatic escaping:
await sql`select * from ${sql.identifier("users")}`;
await sql`select ${sql.identifier("id")} from ${sql.identifier("users")}`;
await sql`select ${sql.identifier(["id", "name", "email"])} from ${sql.identifier("users")}`;
select * from "users";
select "id" from "users";
select "id", "name", "email" from "users";
You can explicitely provide schema
, table
and column
to the query:
tables
columns
columns and tables
const users = sql.identifier({ schema: "public", table: "users" });
await sql`select * from ${users}`;
select * from "public"."users";
SQL identifier has support for as
:
const table = sql.identifier({ schema: "public", table: "users", as: "u" })
const id = sql.identifier({ table: "u", column: "id", as: "userId" });
await sql`select ${columns} from ${table}`;
select "u"."id" as "userId" from "public"."users" "u";