update "users" set "name" = ? where "users"."name" = ?; -- params: ['Mr. Dan', 'Dan']
The object that you pass to update should have keys that match column names in your database schema.
Values of undefined are ignored in the object: to set a column to null, pass null.
Use .orderBy() to add order by clause to the query, sorting the results by the specified fields:
import { asc, desc } from 'drizzle-orm';await db.update(usersTable).set({ verified: true }).orderBy(usersTable.name);await db.update(usersTable).set({ verified: true }).orderBy(desc(usersTable.name));// order by multiple fieldsawait db.update(usersTable).set({ verified: true }).orderBy(usersTable.name, usersTable.name2);await db.update(usersTable).set({ verified: true }).orderBy(asc(usersTable.name), desc(usersTable.name2));
update "users" set "verified" = ? order by "name";update "users" set "verified" = ? order by "name" desc;update "users" set "verified" = ? order by "name", "name2";update "users" set "verified" = ? order by "name" asc, "name2" desc;
with "average_price" as (select avg("price") as "value" from "products") update "products" set "cheap" = true where "products"."price" < (select * from "average_price") returning "id"
Update … from
As the SQLite documentation mentions:
The UPDATE-FROM idea is an extension to SQL that allows an UPDATE statement to be driven by other tables in the database.
The “target” table is the specific table that is being updated. With UPDATE-FROM you can join the target table
against other tables in the database in order to help compute which rows need updating and what
the new values should be on those rows