From e519d69916650472eb248d0ebbb07d2f67b91759 Mon Sep 17 00:00:00 2001 From: Rosetta Roberts Date: Wed, 28 Feb 2024 11:52:02 -0600 Subject: [PATCH] add const to exact comparisons This improves enum support by allowing making `as const` not needed in conditions when creating conditions for columns with enum types. This typescript feature requires typescript 5.0. --- src/db/conditions.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/db/conditions.ts b/src/db/conditions.ts index 5d0a57d..447030b 100644 --- a/src/db/conditions.ts +++ b/src/db/conditions.ts @@ -29,11 +29,11 @@ export const isNotFalse = sql`${self} IS NOT FALSE`; export const isUnknown = sql`${self} IS UNKNOWN`; export const isNotUnknown = sql`${self} IS NOT UNKNOWN`; -export const isDistinctFrom = (a: T) => sql`${self} IS DISTINCT FROM ${conditionalParam(a)}`; -export const isNotDistinctFrom = (a: T) => sql`${self} IS NOT DISTINCT FROM ${conditionalParam(a)}`; +export const isDistinctFrom = (a: T) => sql`${self} IS DISTINCT FROM ${conditionalParam(a)}`; +export const isNotDistinctFrom = (a: T) => sql`${self} IS NOT DISTINCT FROM ${conditionalParam(a)}`; -export const eq = (a: T) => sql`${self} = ${conditionalParam(a)}`; -export const ne = (a: T) => sql`${self} <> ${conditionalParam(a)}`; +export const eq = (a: T) => sql`${self} = ${conditionalParam(a)}`; +export const ne = (a: T) => sql`${self} <> ${conditionalParam(a)}`; export const gt = (a: T) => sql`${self} > ${conditionalParam(a)}`; export const gte = (a: T) => sql`${self} >= ${conditionalParam(a)}`; export const lt = (a: T) => sql`${self} < ${conditionalParam(a)}`; @@ -55,8 +55,8 @@ export const reImatch = (a: T) => sql` export const notReMatch = (a: T) => sql`${self} !~ ${conditionalParam(a)}`; export const notReImatch = (a: T) => sql`${self} !~* ${conditionalParam(a)}`; -export const isIn = (a: readonly T[]) => a.length > 0 ? sql`${self} IN (${vals(a)})` : sql`false`; -export const isNotIn = (a: readonly T[]) => a.length > 0 ? sql`${self} NOT IN (${vals(a)})` : sql`true`; +export const isIn = (a: T) => a.length > 0 ? sql`${self} IN (${vals(a)})` : sql`false`; +export const isNotIn = (a: T) => a.length > 0 ? sql`${self} NOT IN (${vals(a)})` : sql`true`; export const or = (...conditions: (SQLFragment | Whereable)[]) => sql`(${mapWithSeparator(conditions, sql` OR `, c => c)})`; export const and = (...conditions: (SQLFragment | Whereable)[]) => sql`(${mapWithSeparator(conditions, sql` AND `, c => c)})`;