(trx: DbTransaction, tableId: string)
| 57 | |
| 58 | /** Next append position for a table (max(position) + 1, or 0 if empty). */ |
| 59 | export async function nextRowPosition(trx: DbTransaction, tableId: string): Promise<number> { |
| 60 | const [{ maxPos }] = await trx |
| 61 | .select({ |
| 62 | maxPos: sql<number>`coalesce(max(${userTableRows.position}), -1)`.mapWith(Number), |
| 63 | }) |
| 64 | .from(userTableRows) |
| 65 | .where(eq(userTableRows.tableId, tableId)) |
| 66 | return maxPos + 1 |
| 67 | } |
| 68 | |
| 69 | /** Largest `order_key` for a table, or `null` when empty — the append anchor for new keys. */ |
| 70 | export async function maxOrderKey(executor: DbOrTx, tableId: string): Promise<string | null> { |
no test coverage detected