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

Function orderKeyAtSlot

apps/sim/lib/table/rows/ordering.ts:197–215  ·  view source on GitHub ↗
(slot: number)

Source from the content-addressed store, hash-verified

195): Promise<string> {
196 const fractionalOrdering = await isFeatureEnabled('tables-fractional-ordering')
197 const orderKeyAtSlot = async (slot: number): Promise<string | null> => {
198 if (slot < 0) return null
199 if (fractionalOrdering) {
200 const [r] = await trx
201 .select({ orderKey: userTableRows.orderKey })
202 .from(userTableRows)
203 .where(eq(userTableRows.tableId, tableId))
204 .orderBy(asc(userTableRows.orderKey), asc(userTableRows.id))
205 .limit(1)
206 .offset(slot)
207 return r?.orderKey ?? null
208 }
209 const [r] = await trx
210 .select({ orderKey: userTableRows.orderKey })
211 .from(userTableRows)
212 .where(and(eq(userTableRows.tableId, tableId), eq(userTableRows.position, slot)))
213 .limit(1)
214 return r?.orderKey ?? null
215 }
216 if (requestedPosition === undefined) {
217 return keyBetween(await maxOrderKey(trx, tableId), null)
218 }

Callers 1

resolveInsertOrderKeyFunction · 0.85

Calls 1

eqFunction · 0.50

Tested by

no test coverage detected