Skip to content

Commit

Permalink
Merge pull request #183 from ocadoret/master
Browse files Browse the repository at this point in the history
Add conditions with array operators
  • Loading branch information
jawj authored Jan 29, 2025
2 parents 83c970e + 47d1f25 commit f254155
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/db/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export const or = <T>(...conditions: (SQLFragment<any, T> | Whereable)[]) => sql
export const and = <T>(...conditions: (SQLFragment<any, T> | Whereable)[]) => sql<SQL, boolean | null, T>`(${mapWithSeparator(conditions, sql` AND `, c => c)})`;
export const not = <T>(condition: SQLFragment<any, T> | Whereable) => sql<SQL, boolean | null, T>`(NOT ${condition})`;

export const arrayContains = <T>(a: T[] | ParentColumn) => sql<SQL, boolean | null, T>`${self} @> ${conditionalParam(a)}`;
export const arrayContainedIn = <T>(a: T[] | ParentColumn) => sql<SQL, boolean | null, T>`${self} <@ ${conditionalParam(a)}`;
export const arrayOverlaps = <T>(a: T[] | ParentColumn) => sql<SQL, boolean | null, T>`${self} && ${conditionalParam(a)}`;

// things that aren't genuinely conditions
type PluralisingIntervalUnit = 'microsecond' | 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year' | 'decade';
type IntervalUnit = PluralisingIntervalUnit | `${PluralisingIntervalUnit}s` | 'century' | 'centuries' | 'millennium' | 'millennia';
Expand Down

0 comments on commit f254155

Please sign in to comment.