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

Function checkConditions

apps/sim/lib/table/validation.ts:474–494  ·  view source on GitHub ↗
(ex: UniqueCheckExecutor)

Source from the content-addressed store, hash-verified

472 // inside the caller's would be the nested pool checkout the migration-
473 // hardening work eliminated (self-deadlock under pool exhaustion).
474 const checkConditions = async (ex: UniqueCheckExecutor) => {
475 for (const condition of conditions) {
476 const baseCondition = and(eq(userTableRows.tableId, tableId), condition.sql)
477
478 const whereClause = excludeRowId
479 ? and(baseCondition, sql`${userTableRows.id} != ${excludeRowId}`)
480 : baseCondition
481
482 const conflictingRow = await ex
483 .select({ id: userTableRows.id, position: userTableRows.position })
484 .from(userTableRows)
485 .where(whereClause)
486 .limit(1)
487
488 if (conflictingRow.length > 0) {
489 errors.push(
490 `Column "${condition.column.name}" must be unique. Value "${condition.value}" already exists in row ${conflictingRow[0].position + 1}`
491 )
492 }
493 }
494 }
495
496 if (executor === db) {
497 await withSeqscanOff(async (trx) => checkConditions(trx))

Callers 1

checkUniqueConstraintsDbFunction · 0.85

Calls 2

eqFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected