({
tableDef,
workspaceIdCol,
timestampCol,
workspaceIds,
retentionDate,
tableName,
requireTimestampNotNull = false,
...rest
}: BatchDeleteOptions)
| 197 | * when there's no per-row side effect (e.g. no S3 files to clean up alongside). |
| 198 | */ |
| 199 | export async function batchDeleteByWorkspaceAndTimestamp({ |
| 200 | tableDef, |
| 201 | workspaceIdCol, |
| 202 | timestampCol, |
| 203 | workspaceIds, |
| 204 | retentionDate, |
| 205 | tableName, |
| 206 | requireTimestampNotNull = false, |
| 207 | ...rest |
| 208 | }: BatchDeleteOptions): Promise<TableCleanupResult> { |
| 209 | return chunkedBatchDelete({ |
| 210 | tableDef, |
| 211 | workspaceIds, |
| 212 | tableName, |
| 213 | selectChunk: (chunkIds, limit) => { |
| 214 | const predicates = [inArray(workspaceIdCol, chunkIds), lt(timestampCol, retentionDate)] |
| 215 | if (requireTimestampNotNull) predicates.push(isNotNull(timestampCol)) |
| 216 | return db |
| 217 | .select({ id: sql<string>`id` }) |
| 218 | .from(tableDef) |
| 219 | .where(and(...predicates)) |
| 220 | .limit(limit) |
| 221 | }, |
| 222 | ...rest, |
| 223 | }) |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Delete by explicit ID list, chunked so each statement is its own transaction. |
no test coverage detected