( tableId: string, workspaceId: string, rowIds: string[], patchJson: string )
| 615 | * makes incremental, resumable progress. Returns the number of rows updated. |
| 616 | */ |
| 617 | export async function updatePageByIds( |
| 618 | tableId: string, |
| 619 | workspaceId: string, |
| 620 | rowIds: string[], |
| 621 | patchJson: string |
| 622 | ): Promise<number> { |
| 623 | const now = new Date() |
| 624 | let updated = 0 |
| 625 | for (let i = 0; i < rowIds.length; i += TABLE_LIMITS.UPDATE_BATCH_SIZE) { |
| 626 | const batch = rowIds.slice(i, i + TABLE_LIMITS.UPDATE_BATCH_SIZE) |
| 627 | const rows = await db.transaction(async (trx) => { |
| 628 | await setTableTxTimeouts(trx, { statementMs: 60_000 }) |
| 629 | return trx |
| 630 | .update(userTableRows) |
| 631 | .set({ data: sql`${userTableRows.data} || ${patchJson}::jsonb`, updatedAt: now }) |
| 632 | .where( |
| 633 | and( |
| 634 | eq(userTableRows.tableId, tableId), |
| 635 | eq(userTableRows.workspaceId, workspaceId), |
| 636 | inArray(userTableRows.id, batch) |
| 637 | ) |
| 638 | ) |
| 639 | .returning({ id: userTableRows.id }) |
| 640 | }) |
| 641 | updated += rows.length |
| 642 | } |
| 643 | return updated |
| 644 | } |
no test coverage detected