Unable to delete all rows from SQLite using Transactions?

i have a route api/delete-all that looks like:

import { NextResponse } from 'next/server'

import { users, sessions, keys, emailVerificationTokens } from '@/app/db/schema'
import { db } from '@/app/db/index'

export const DELETE = async () => {
  console.log('🏁 /api/delete')
  try {
    await db.transaction(async (tx) => {
      const deletedUsers = tx.delete(users)
      const deletedSessions = tx.delete(sessions)
      const deletedKeys = tx.delete(keys)
      const deletedEmailVerificationTokens = tx.delete(emailVerificationTokens)

      console.log({
        deletedUsers,
        deletedSessions,
        deletedKeys,
        deletedEmailVerificationTokens,
      })
    })
  } catch (error) {
    return NextResponse.json({ error, success: false })
  }
  return NextResponse.json({ success: true })
}


i want to delete all values but i get a SQLITE_CONSTRAINT_ERROR:

error: {code: "SQLITE_CONSTRAINT", name: "LibsqlError"}


how do i delete all rows in a table?

i tried without transactions as well as using await tx.delete(users).all() but it doesn't delete from the database.

i'm using https://turso.tech for sqlite on the edge.
Eliminate application bottlenecks by bringing the performance and data portability of open source, lightweight SQL close to your users with low overhead
Was this page helpful?