MCPcopy Index your code
hub / github.com/simstudioai/sim / reserveInsertPosition

Function reserveInsertPosition

apps/sim/lib/table/rows/ordering.ts:100–118  ·  view source on GitHub ↗
(
  trx: DbTransaction,
  tableId: string,
  requestedPosition?: number
)

Source from the content-addressed store, hash-verified

98 * transaction.
99 */
100export 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

Callers 1

upsertRowFunction · 0.90

Calls 4

acquireRowOrderLockFunction · 0.85
nextRowPositionFunction · 0.85
shiftRowsUpFromFunction · 0.85
eqFunction · 0.50

Tested by

no test coverage detected