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

Function nextRowPosition

apps/sim/lib/table/rows/ordering.ts:59–67  ·  view source on GitHub ↗
(trx: DbTransaction, tableId: string)

Source from the content-addressed store, hash-verified

57
58/** Next append position for a table (max(position) + 1, or 0 if empty). */
59export 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. */
70export async function maxOrderKey(executor: DbOrTx, tableId: string): Promise<string | null> {

Callers 4

batchInsertRowsWithTxFunction · 0.90
reserveInsertPositionFunction · 0.85
reserveBatchPositionsFunction · 0.85
insertOrderedRowFunction · 0.85

Calls 1

eqFunction · 0.50

Tested by

no test coverage detected