OptionalwithList: Subquery<string, Record<string, unknown>>[]Readonly_Static Readonly[entityA Promise for the completion of the callback.
Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.
OptionalonFinally: (() => void) | nullA Promise for the completion of the callback.
Adds a returning clause to the query.
Calling this method will return the specified fields of the updated rows. If no fields are specified, all fields will be returned.
See docs: https://orm.drizzle.team/docs/update#update-with-returning
// Update all cars with the green color and return all fields
const updatedCars: Car[] = await db.update(cars)
.set({ color: 'red' })
.where(eq(cars.color, 'green'))
.returning();
// Update all cars with the green color and return only their id and brand fields
const updatedCarsIdsAndBrands: { id: number, brand: string }[] = await db.update(cars)
.set({ color: 'red' })
.where(eq(cars.color, 'green'))
.returning({ id: cars.id, brand: cars.brand });
Adds a returning clause to the query.
Calling this method will return the specified fields of the updated rows. If no fields are specified, all fields will be returned.
See docs: https://orm.drizzle.team/docs/update#update-with-returning
// Update all cars with the green color and return all fields
const updatedCars: Car[] = await db.update(cars)
.set({ color: 'red' })
.where(eq(cars.color, 'green'))
.returning();
// Update all cars with the green color and return only their id and brand fields
const updatedCarsIdsAndBrands: { id: number, brand: string }[] = await db.update(cars)
.set({ color: 'red' })
.where(eq(cars.color, 'green'))
.returning({ id: cars.id, brand: cars.brand });
OptionalshouldAttaches callbacks for the resolution and/or rejection of the Promise.
OptionalonFulfilled: OptionalonRejected: ((reason: any) => TResult2 | PromiseLike<TResult2>) | nullA Promise for the completion of which ever callback is executed.
Adds a 'where' clause to the query.
Calling this method will update only those rows that fulfill a specified condition.
See docs: https://orm.drizzle.team/docs/update
the 'where' clause.
You can use conditional operators and sql function to filter the rows to be updated.
// Update all cars with green color
db.update(cars).set({ color: 'red' })
.where(eq(cars.color, 'green'));
// or
db.update(cars).set({ color: 'red' })
.where(sql`${cars.color} = 'green'`)
You can logically combine conditional operators with and() and or() operators:
// Update all BMW cars with a green color
db.update(cars).set({ color: 'red' })
.where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
// Update all cars with the green or blue color
db.update(cars).set({ color: 'red' })
.where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
Attaches a callback for only the rejection of the Promise.