Skip to content

Commit e26a5a6

Browse files
j15zclaude
andcommitted
refactor(tables): migrate JSONB cast lookup to the column-type registry
jsonbCastForType's switch is replaced by a delegate to the new registry's sqlCastForColumnType, so a new column type's sort/filter cast only needs to be declared once, in column-types.ts. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 6b45546 commit e26a5a6

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

apps/sim/lib/table/sql.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { isRecordLike } from '@sim/utils/object'
99
import type { SQL } from 'drizzle-orm'
1010
import { sql } from 'drizzle-orm'
1111
import { getColumnId } from '@/lib/table/column-keys'
12+
import { sqlCastForColumnType } from '@/lib/table/column-types'
1213
import { NAME_PATTERN } from '@/lib/table/constants'
1314
import { TableQueryValidationError } from '@/lib/table/errors'
1415
import type {
@@ -68,17 +69,12 @@ const MULTI_SELECT_OPS = new Set<FilterOp>([
6869
* Returns the Postgres cast needed to compare a JSONB text value of the given
6970
* column type, or `null` when text comparison is correct. Single source of
7071
* truth for both filter range operators and sort ordering — keeps the two
71-
* paths from drifting apart.
72+
* paths from drifting apart. Delegates to the column-type registry
73+
* (`column-types.ts`) so a new column type's cast rule only needs to be added
74+
* in one place — see `ColumnTypeDefinition.sqlCast`.
7275
*/
7376
function jsonbCastForType(type: ColumnType | undefined): 'numeric' | 'timestamptz' | null {
74-
switch (type) {
75-
case 'number':
76-
return 'numeric'
77-
case 'date':
78-
return 'timestamptz'
79-
default:
80-
return null
81-
}
77+
return sqlCastForColumnType(type)
8278
}
8379

8480
/**

0 commit comments

Comments
 (0)