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

Function validateComparisonValue

apps/sim/lib/table/sql.ts:269–286  ·  view source on GitHub ↗

* Validates that a range-operator value matches its column's expected JS type * before it reaches Postgres. Surfaces an actionable, column-named error at the * SQL builder layer instead of a generic `invalid input syntax for type numeric` * from the database.

(
  field: string,
  columnType: ColumnType | undefined,
  cast: 'numeric' | 'timestamptz',
  value: number | string
)

Source from the content-addressed store, hash-verified

267 * from the database.
268 */
269function validateComparisonValue(
270 field: string,
271 columnType: ColumnType | undefined,
272 cast: 'numeric' | 'timestamptz',
273 value: number | string
274): void {
275 if (cast === 'numeric' && typeof value !== 'number') {
276 const label = columnType ?? 'number'
277 throw new TableQueryValidationError(
278 `Range operator on column "${field}" (${label}) requires a number, got ${typeof value}`
279 )
280 }
281 if (cast === 'timestamptz' && typeof value !== 'string') {
282 throw new TableQueryValidationError(
283 `Range operator on column "${field}" (date) requires a date string, got ${typeof value}`
284 )
285 }
286}
287
288/**
289 * Builds SQL conditions for a single field based on the provided condition.

Callers 1

buildComparisonClauseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected