Skip to content

Commit

Permalink
fix: datetime isNot filter (#1158)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpodp0ra authored Dec 12, 2024
1 parent c09f58d commit 3968cab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ export class MultipleDatetimeCellValueFilterAdapter extends CellValueFilterPostg
const { options } = this.field;

const dateTimeRange = this.getFilterDateTimeRange(options as IDateFieldOptions, value);
builderClient
.whereRaw(
`NOT ??::jsonb @\\? '$[*] \\? (@ >= "${dateTimeRange[0]}" && @ <= "${dateTimeRange[1]}")'`,
[this.tableColumnRef]
)
.orWhereNull(this.tableColumnRef);
builderClient.where((builder) => {
builder
.whereRaw(
`NOT ??::jsonb @\\? '$[*] \\? (@ >= "${dateTimeRange[0]}" && @ <= "${dateTimeRange[1]}")'`,
[this.tableColumnRef]
)
.orWhereNull(this.tableColumnRef);
});

return builderClient;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ export class DatetimeCellValueFilterAdapter extends CellValueFilterPostgres {
const { options } = this.field;

const dateTimeRange = this.getFilterDateTimeRange(options as IDateFieldOptions, value);
builderClient
.whereNotBetween(this.tableColumnRef, dateTimeRange)
.orWhereNull(this.tableColumnRef);

// Wrap conditions in a nested `.where()` to ensure proper SQL grouping with parentheses,
// generating `WHERE ("data" NOT BETWEEN ... OR "data" IS NULL) AND other_query`.
builderClient.where((builder) => {
builder.whereNotBetween(this.tableColumnRef, dateTimeRange).orWhereNull(this.tableColumnRef);
});
return builderClient;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class DatetimeCellValueFilterAdapter extends CellValueFilterSqlite {
const { options } = this.field;

const dateTimeRange = this.getFilterDateTimeRange(options as IDateFieldOptions, value);
builderClient
.whereNotBetween(this.tableColumnRef, dateTimeRange)
.orWhereNull(this.tableColumnRef);
builderClient.where((builder) => {
builder.whereNotBetween(this.tableColumnRef, dateTimeRange).orWhereNull(this.tableColumnRef);
});
return builderClient;
}

Expand Down

0 comments on commit 3968cab

Please sign in to comment.