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

cockroach/delete

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

Delete all rows from a table

To delete all rows from a table, use `await db.delete(users);` with no filters.

Delete and return deleted rows in CockroachDB

You can use `.returning()` on a delete operation to retrieve the deleted rows. For example: `const deletedUser = await db.delete(users).where(eq(users.name, 'Dan')).returning();` returns all columns of deleted rows.

Delete with partial column return

You can specify which columns to return from deleted rows using `.returning({ deletedId: users.id });`. This returns an array of objects with only the specified columns.

Delete with CTE (Common Table Expression)

You can use the `with` clause in delete operations to simplify complex queries by splitting them into CTEs. Create a CTE with `db.$with('average_amount').as(...)`, then use it in the delete: `db.with(averageAmount).delete(orders).where(...).returning(...)`

Delete with CTE example

Example of delete with CTE: const averageAmount = db.$with('average_amount').as(db.select({ value: sql`avg(${orders.amount})`.as('value') }).from(orders)); const result = await db.with(averageAmount).delete(orders).where(gt(orders.amount, sql`(select * from ${averageAmount})`)).returning({ id: orders.id });

Give your agent this brain