Skip to content

Commit b458727

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 32b9566 commit b458727

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 type {
1415
ColumnDefinition,
@@ -47,17 +48,12 @@ export const MULTI_SELECT_OPERATORS = new Set(['$contains', '$ncontains', '$empt
4748
* Returns the Postgres cast needed to compare a JSONB text value of the given
4849
* column type, or `null` when text comparison is correct. Single source of
4950
* truth for both filter range operators and sort ordering — keeps the two
50-
* paths from drifting apart.
51+
* paths from drifting apart. Delegates to the column-type registry
52+
* (`column-types.ts`) so a new column type's cast rule only needs to be added
53+
* in one place — see `ColumnTypeDefinition.sqlCast`.
5154
*/
5255
function jsonbCastForType(type: ColumnType | undefined): 'numeric' | 'timestamptz' | null {
53-
switch (type) {
54-
case 'number':
55-
return 'numeric'
56-
case 'date':
57-
return 'timestamptz'
58-
default:
59-
return null
60-
}
56+
return sqlCastForColumnType(type)
6157
}
6258

6359
/**

0 commit comments

Comments
 (0)