Update
update() modifies matching rows. Pair it with where() to scope the update.
Update with a filter
Section titled “Update with a filter”await db.from(users).where("id", "=", 1).update({ age: 37 });Update without a filter (all rows)
Section titled “Update without a filter (all rows)”Omit where() to update every row:
await db.from(users).update({ active: true });Read back with returning()
Section titled “Read back with returning()”const { rows } = await db .from(users) .where("id", "=", 1) .returning("email") .update({ age: 37 });How it compiles
Section titled “How it compiles”db.from(users).where("id", "=" , 1).update({ age: 37 });// → UPDATE "users" SET "age" = ? WHERE "id" = ?Real-world example
Section titled “Real-world example”export async function renameUser(id: number, email: string) { await db.from(users).where("id", "=", id).update({ email });}Best practices
Section titled “Best practices”- Always add
where()unless you mean to update the whole table. - Use
returning()to confirm what changed. - Bind values — MountSQLI never interpolates them.
Common mistakes
Section titled “Common mistakes”- Forgetting
where()and updating all rows. - Reusing a builder after a terminal call expecting more chaining.
