superapp
ClientQueries

Delete

Delete one or more rows matching a condition.

Use db.delete() to remove rows matching a condition.

import { drizzle } from '@superapp/db'
import { eq } from 'drizzle-orm'
import * as schema from './generated/schema'

const db = drizzle({ connection, token, schema })

// The backend scopes this to the logged-in user's data.
// You can only delete your own rows — attempting to delete
// another user's order simply won't match any rows.
await db.delete(schema.orders)
  .where(eq(schema.orders.id, 'ord_abc123'))

Delete with Returning

const [deleted] = await db.delete(schema.orders)
  .where(eq(schema.orders.id, 'ord_abc123'))
  .returning()
// deleted: { id, amount, status, ... }

Filtered Delete

Delete multiple rows matching a condition.

await db.delete(schema.orders)
  .where(eq(schema.orders.status, 'cancelled'))

Delete with Complex Filters

import { eq, lt, and } from 'drizzle-orm'

await db.delete(schema.orders)
  .where(and(
    eq(schema.orders.status, 'expired'),
    lt(schema.orders.createdAt, new Date('2023-01-01'))
  ))

On this page