-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix(tables): fix the filter on built in timestamp columns #5972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import type { | |
| JsonValue, | ||
| Sort, | ||
| } from '@/lib/table/types' | ||
| import { isBuiltInDateField } from '@/app/api/table/utils.ts' | ||
|
|
||
| /** | ||
| * Error thrown when caller-supplied filter or sort input is malformed. | ||
|
|
@@ -380,7 +381,9 @@ function buildFieldCondition( | |
|
|
||
| case '$ncontains': | ||
| conditions.push( | ||
| buildLikeClause(tableName, field, value as string, 'contains', { negate: true }) | ||
| buildLikeClause(tableName, field, value as string, 'contains', { | ||
| negate: true, | ||
| }) | ||
| ) | ||
| break | ||
|
|
||
|
|
@@ -458,8 +461,15 @@ function buildLogicalClause( | |
|
|
||
| /** Builds JSONB containment clause: `data @> '{"field": value}'::jsonb` (uses GIN index) */ | ||
| function buildContainmentClause(tableName: string, field: string, value: JsonValue): SQL { | ||
| if (isBuiltInDateField(field)) { | ||
| return sql`${sql.raw(`${tableName}.${field}`)} = ${value}::timestamptz` | ||
| } | ||
|
|
||
| const jsonObj = JSON.stringify({ [field]: value }) | ||
| return sql`${sql.raw(`${tableName}.data`)} @> ${jsonObj}::jsonb` | ||
|
|
||
| // const jsonObj = JSON.stringify({ [field]: value }) | ||
| // return sql`${sql.raw(`${tableName}.data`)} @> ${jsonObj}::jsonb` | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -485,10 +495,17 @@ function buildComparisonClause( | |
| value: number | string, | ||
| columnType: ColumnType | undefined | ||
| ): SQL { | ||
| if (isBuiltInDateField(field)) { | ||
| columnType = 'date' | ||
| } | ||
|
|
||
| const escapedField = field.replace(/'/g, "''") | ||
| const cast = jsonbCastForType(columnType) ?? 'numeric' | ||
| validateComparisonValue(field, columnType, cast, value) | ||
| const cell = sql.raw(`(${tableName}.data->>'${escapedField}')::${cast}`) | ||
|
|
||
| const cell = isBuiltInDateField(field) | ||
| ? sql.raw(`${tableName}.${field}`) | ||
| : sql.raw(`(${tableName}.data->>'${escapedField}')::${cast}`) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CamelCase fields hit wrong SQL columnsHigh Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit 56cb60b. Configure here.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the columns created_at/updated_at exist by default in a table. while fetching rows by query_rows, they exist in row.created_at/row.updated_at not inside row.data.columnName as for normal columns. |
||
| return cast === 'timestamptz' | ||
| ? sql`${cell} ${sql.raw(operator)} ${value}::timestamptz` | ||
| : sql`${cell} ${sql.raw(operator)} ${value}` | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.