MCPcopy
hub / github.com/simstudioai/sim / withLockedTable

Function withLockedTable

apps/sim/lib/table/service.ts:60–76  ·  view source on GitHub ↗
(
  tableId: string,
  mutate: (table: TableDefinition, trx: DbTransaction) => Promise<T>,
  opts?: { includeArchived?: boolean }
)

Source from the content-addressed store, hash-verified

58 * `statement_timeout` set in `setTableTxTimeouts`.
59 */
60export async function withLockedTable<T>(
61 tableId: string,
62 mutate: (table: TableDefinition, trx: DbTransaction) => Promise<T>,
63 opts?: { includeArchived?: boolean }
64): Promise<T> {
65 return db.transaction(async (trx) => {
66 await setTableTxTimeouts(trx)
67 await trx.execute(
68 sql`SELECT pg_advisory_xact_lock(hashtextextended(${`user_table_schema:${tableId}`}, 0))`
69 )
70 const table = await getTableById(tableId, { tx: trx, includeArchived: opts?.includeArchived })
71 if (!table) {
72 throw new Error('Table not found')
73 }
74 return mutate(table, trx)
75 })
76}
77
78/**
79 * Returns `schema` with `columns` sorted by `metadata.columnOrder` (the user-

Callers 11

addWorkflowGroupFunction · 0.90
updateWorkflowGroupFunction · 0.90
addWorkflowGroupOutputFunction · 0.90
deleteWorkflowGroupFunction · 0.90
addTableColumnFunction · 0.90
renameColumnFunction · 0.90
deleteColumnFunction · 0.90
deleteColumnsFunction · 0.90
updateColumnTypeFunction · 0.90
updateColumnConstraintsFunction · 0.90

Calls 3

setTableTxTimeoutsFunction · 0.90
getTableByIdFunction · 0.85
executeMethod · 0.65

Tested by

no test coverage detected