Files
payload/packages/db-postgres/src/upsertRow/deleteExistingArrayRows.ts

24 lines
483 B
TypeScript

import { and, eq } from 'drizzle-orm'
import type { DrizzleDB, PostgresAdapter } from '../types.js'
type Args = {
adapter: PostgresAdapter
db: DrizzleDB
parentID: unknown
tableName: string
}
export const deleteExistingArrayRows = async ({
adapter,
db,
parentID,
tableName,
}: Args): Promise<void> => {
const table = adapter.tables[tableName]
const whereConstraints = [eq(table._parentID, parentID)]
await db.delete(table).where(and(...whereConstraints))
}