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.
You can pass SQL as a value to be used in the update object, like this:
Limit
PostgreSQL
MySQL
SQLite
Use .limit() to add limit clause to the query - for example:
Order By
Use .orderBy() to add order by clause to the query, sorting the results by the specified fields:
Update with returning
PostgreSQL
SQLite
MySQL
You can update a row and get it back in PostgreSQL and SQLite:
Using the with clause can help you simplify complex queries by splitting them into smaller subqueries called common table expressions (CTEs):
Update … from
PostgreSQL
MySQL
SQLite
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
Similarly, the PostgreSQL documentation states:
A table expression allowing columns from other tables to appear in the WHERE condition and update expressions
Drizzle also supports this feature starting from version [email protected]
You can also alias tables that are joined (in PG, you can also alias the updating table too).
PostgreSQL
MySQL
SQLite
In Postgres, you can also return columns from the joined tables.