new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Drizzle ORM · all subjects

delete & update operations

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Update with SQL-like syntax

Example of update: `await db.update(users).set({ email: 'user@gmail.com' }).where(eq(users.id, 1))` generates `UPDATE users SET email = 'user@gmail.com' WHERE users.id = 1`.

Delete with SQL-like syntax

Example of delete: `await db.delete(users).where(eq(users.id, 1))` generates `DELETE FROM users WHERE users.id = 1`.

Delete all rows from a table

To delete all rows from a table, use await db.delete(tableName).

Delete rows with WHERE clause

To delete rows with conditions, chain .where() after db.delete(). For example: await db.delete(users).where(eq(users.name, 'Dan')).

Delete with LIMIT clause

Use .limit() to add a limit clause to a delete query. For example: await db.delete(users).where(eq(users.name, 'Dan')).limit(2) produces the SQL delete from `users` where `users`.`name` = 'Dan' limit 2.

Delete with ORDER BY clause

Use .orderBy() to add an order by clause to a delete query. You can sort by a single field: await db.delete(users).where(eq(users.name, 'Dan')).orderBy(users.name). Use desc() from drizzle-orm for descending order: await db.delete(users).where(eq(users.name, 'Dan')).orderBy(desc(users.name)). For multiple fields, pass them as arguments: await db.delete(users).where(eq(users.name, 'Dan')).orderBy(users.name, users.name2). Mix asc and desc for each field: await db.delete(users).where(eq(users.name, 'Dan')).orderBy(asc(users.name), desc(users.name2)).

Import asc and desc for ORDER BY

The asc and desc functions must be imported from 'drizzle-orm' to use with .orderBy() in delete queries.

Give your agent this brain