sql
sql.identifier
sql.values
sql.raw
sql.default
toSQL
stream
chunked
sql.values lets you conveniently pass values to insert statements:
await sql`insert into "users" ("name") values ${sql.values([["Dan"]])}`; const values = sql.values([["Dan", "[email protected]", 25]]); await sql`insert into "users" ("name", "email", "age") values ${values}`;
insert into "users" ("name") values ('Dan'); insert into "users" ("name") values ('Dan', '[email protected]', 25);
const values = sql.values([ ["Dan", "[email protected]", 25], ["Oleksii", "[email protected]", 22] ]); await sql`insert into "users" ("name", "email", "age") values ${values}`;
insert into "users" ("name", "email", "age") values ('Dan', '[email protected]', 25), ('Oleksii', '[email protected]', 22);
Waddler provides a convinient sql.default for SQL DEFAULT values:
DEFAULT
const values = sql.values([["Dan", sql.default], ["Alex", sql.default]]) await sql`insert into "users" ("name", "created_at") values ${values}`;
insert into "users" ("name", "created_at") values ('Dan', default), ('Alex', default);
Complete example with sql.identifier and sql.default:
const table = sql.identifier("users") const columns = sql.identifier(["id", "name", "age"]); const values = sql.values([ [sql.default, "Oleksii", 20], [sql.default, "Alex", 23], ]); await sql`insert into ${table} (${columns}) values ${values} returning ${columns};`;
insert into "users" ("id", "name", "age") values (default, 'Oleksii', 20), (default, 'Alex', 23);