( trx: DbTransaction, tableId: string, requestedPosition?: number )
| 98 | * transaction. |
| 99 | */ |
| 100 | export async function reserveInsertPosition( |
| 101 | trx: DbTransaction, |
| 102 | tableId: string, |
| 103 | requestedPosition?: number |
| 104 | ): Promise<number> { |
| 105 | await acquireRowOrderLock(trx, tableId) |
| 106 | if (requestedPosition === undefined) { |
| 107 | return nextRowPosition(trx, tableId) |
| 108 | } |
| 109 | const [existing] = await trx |
| 110 | .select({ id: userTableRows.id }) |
| 111 | .from(userTableRows) |
| 112 | .where(and(eq(userTableRows.tableId, tableId), eq(userTableRows.position, requestedPosition))) |
| 113 | .limit(1) |
| 114 | if (existing) { |
| 115 | await shiftRowsUpFrom(trx, tableId, requestedPosition) |
| 116 | } |
| 117 | return requestedPosition |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Reserves positions for a batch of `count` rows. Opens each requested slot |
no test coverage detected