SQL default

This guide assumes familiarity with:

sql.default lets you conveniently use SQL DEFAULT values in queries:

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);