Files
payload/packages/db-postgres/src/upsertRow/deleteExistingArrayRows.ts
2023-09-21 12:18:10 -04:00

24 lines
480 B
TypeScript

import { and, eq } from 'drizzle-orm'
import type { DrizzleDB, PostgresAdapter } from '../types'
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))
}