( data: ReplaceRowsData, table: TableDefinition, requestId: string )
| 356 | * @throws Error if validation fails or capacity exceeded |
| 357 | */ |
| 358 | export async function replaceTableRows( |
| 359 | data: ReplaceRowsData, |
| 360 | table: TableDefinition, |
| 361 | requestId: string |
| 362 | ): Promise<ReplaceRowsResult> { |
| 363 | // All existing rows are deleted, so the footprint is just the new set. Checked |
| 364 | // before the tx opens — never inside it (the plan lookup is a separate pool read). |
| 365 | const rowLimit = await assertRowCapacity({ |
| 366 | workspaceId: table.workspaceId, |
| 367 | currentRowCount: 0, |
| 368 | addedRows: data.rows.length, |
| 369 | }) |
| 370 | const result = await db.transaction((trx) => replaceTableRowsWithTx(trx, data, table, requestId)) |
| 371 | notifyTableRowUsage({ |
| 372 | workspaceId: table.workspaceId, |
| 373 | currentRowCount: 0, |
| 374 | addedRows: result.insertedCount, |
| 375 | limit: rowLimit, |
| 376 | }) |
| 377 | return result |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Transaction-bound variant of `replaceTableRows`. Caller opens the transaction. |
no test coverage detected