tsql
.md

Mutations

Insert

await db
	.insert("users")
	.values({
		email: "alice@example.com",
		name: "Alice",
		createdAt: new Date("2026-01-01T00:00:00.000Z"),
	})
	.execute();

Batch insert:

await db
	.insert("users")
	.values([
		{ email: "alice@example.com", name: "Alice", createdAt: new Date("2026-01-01T00:00:00.000Z") },
		{ email: "bob@example.com", name: "Bob", createdAt: new Date("2026-01-02T00:00:00.000Z") },
	])
	.execute();

Insert from a typed select:

await db
	.insert("users_archive")
	.from(
		db.from("users").select(({ users }) => ({
			id: users.id,
			email: users.email,
		})),
	)
	.execute();

The select aliases become the target column names. Both names and projected value types are checked against the target table.

Update

await db
	.update("users")
	.where(({ users }) => users.id.eq(1, db.dialect))
	.set({ name: "Alice Updated" })
	.execute();

Delete

await db
	.delete("users")
	.where(({ users }) => users.id.eq(5, db.dialect))
	.execute();

Notes