-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Array operators as conditions #164
Comments
This seems to work? At least in my very limited prototyping. export const arrayContains = <T>(a: readonly T[]) =>
a.length > 0 ? sql<SQL, boolean | null, T[]>`${self} @> ARRAY[${vals(a)}]` : sql`false`;
export const arrayIsContained = <T>(a: readonly T[]) =>
a.length > 0 ? sql<SQL, boolean | null, T[]>`${self} <@ ARRAY[${vals(a)}]` : sql`false`;
export const arrayOverlaps = <T>(a: readonly T[]) =>
a.length > 0 ? sql<SQL, boolean | null, T[]>`${self} && ARRAY[${vals(a)}]` : sql`false`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Postgres supports a few array operators that I think would fit as conditions: https://www.postgresql.org/docs/16/functions-array.html
Specifically the
@>
,<@
, and&&
operators. I'm not entirely certain if it's possible to typecheck that the left-hand column is an array, but the actual implementation should be fairly straightforward? Something similar to this?That syntax is probably slightly off. I'll probably end up making these for myself and can happily put up a PR once I have them functional.
The text was updated successfully, but these errors were encountered: