From 3a93c63b2f870171be17b4ef47963bfb49ae83b6 Mon Sep 17 00:00:00 2001 From: Mario564 Date: Thu, 15 Aug 2024 22:53:04 -0700 Subject: [PATCH] Support more types in text comparing sql expressions --- drizzle-orm/src/sql/expressions/conditions.ts | 8 ++++---- drizzle-orm/type-tests/mysql/with.ts | 5 ++++- drizzle-orm/type-tests/pg/with.ts | 5 ++++- drizzle-orm/type-tests/sqlite/with.ts | 5 ++++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/drizzle-orm/src/sql/expressions/conditions.ts b/drizzle-orm/src/sql/expressions/conditions.ts index ba0e21fbc..7ad1355dd 100644 --- a/drizzle-orm/src/sql/expressions/conditions.ts +++ b/drizzle-orm/src/sql/expressions/conditions.ts @@ -526,7 +526,7 @@ export function notBetween( * * @see ilike for a case-insensitive version of this condition */ -export function like(column: Column, value: string | SQLWrapper): SQL { +export function like(column: Column | SQL.Aliased | SQL, value: string | SQLWrapper): SQL { return sql`${column} like ${value}`; } @@ -548,7 +548,7 @@ export function like(column: Column, value: string | SQLWrapper): SQL { * @see like for the inverse condition * @see notIlike for a case-insensitive version of this condition */ -export function notLike(column: Column, value: string | SQLWrapper): SQL { +export function notLike(column: Column | SQL.Aliased | SQL, value: string | SQLWrapper): SQL { return sql`${column} not like ${value}`; } @@ -571,7 +571,7 @@ export function notLike(column: Column, value: string | SQLWrapper): SQL { * * @see like for a case-sensitive version of this condition */ -export function ilike(column: Column, value: string | SQLWrapper): SQL { +export function ilike(column: Column | SQL.Aliased | SQL, value: string | SQLWrapper): SQL { return sql`${column} ilike ${value}`; } @@ -593,7 +593,7 @@ export function ilike(column: Column, value: string | SQLWrapper): SQL { * @see ilike for the inverse condition * @see notLike for a case-sensitive version of this condition */ -export function notIlike(column: Column, value: string | SQLWrapper): SQL { +export function notIlike(column: Column | SQL.Aliased | SQL, value: string | SQLWrapper): SQL { return sql`${column} not ilike ${value}`; } diff --git a/drizzle-orm/type-tests/mysql/with.ts b/drizzle-orm/type-tests/mysql/with.ts index b4e528191..e6f240489 100644 --- a/drizzle-orm/type-tests/mysql/with.ts +++ b/drizzle-orm/type-tests/mysql/with.ts @@ -1,6 +1,6 @@ import type { Equal } from 'type-tests/utils.ts'; import { Expect } from 'type-tests/utils.ts'; -import { gt, inArray } from '~/expressions.ts'; +import { gt, inArray, like } from '~/expressions.ts'; import { int, mysqlTable, serial, text } from '~/mysql-core/index.ts'; import { sql } from '~/sql/sql.ts'; import { db } from './db.ts'; @@ -77,4 +77,7 @@ const orders = mysqlTable('orders', { generated: string | null; }[], typeof allFromWith> >; + + const regionalSalesWith = db.$with('regional_sales_with').as(db.select().from(regionalSales)); + db.with(regionalSalesWith).select().from(regionalSalesWith).where(like(regionalSalesWith.totalSales, 'abc')); } diff --git a/drizzle-orm/type-tests/pg/with.ts b/drizzle-orm/type-tests/pg/with.ts index d5fcc96ed..288e3b6d0 100644 --- a/drizzle-orm/type-tests/pg/with.ts +++ b/drizzle-orm/type-tests/pg/with.ts @@ -1,6 +1,6 @@ import type { Equal } from 'type-tests/utils.ts'; import { Expect } from 'type-tests/utils.ts'; -import { gt, inArray } from '~/expressions.ts'; +import { gt, inArray, like } from '~/expressions.ts'; import { integer, pgTable, serial, text } from '~/pg-core/index.ts'; import { sql } from '~/sql/sql.ts'; import { db } from './db.ts'; @@ -77,4 +77,7 @@ const orders = pgTable('orders', { generated: string | null; }[], typeof allFromWith> >; + + const regionalSalesWith = db.$with('regional_sales_with').as(db.select().from(regionalSales)); + db.with(regionalSalesWith).select().from(regionalSalesWith).where(like(regionalSalesWith.totalSales, 'abc')); } diff --git a/drizzle-orm/type-tests/sqlite/with.ts b/drizzle-orm/type-tests/sqlite/with.ts index 8b5963eb6..b26e4e7d7 100644 --- a/drizzle-orm/type-tests/sqlite/with.ts +++ b/drizzle-orm/type-tests/sqlite/with.ts @@ -1,6 +1,6 @@ import type { Equal } from 'type-tests/utils.ts'; import { Expect } from 'type-tests/utils.ts'; -import { gt, inArray } from '~/expressions.ts'; +import { gt, inArray, like } from '~/expressions.ts'; import { sql } from '~/sql/sql.ts'; import { integer, sqliteTable, text } from '~/sqlite-core/index.ts'; import { db } from './db.ts'; @@ -78,4 +78,7 @@ const orders = sqliteTable('orders', { generated: string | null; }[], typeof allFromWith> >; + + const regionalSalesWith = db.$with('regional_sales_with').as(db.select().from(regionalSales)); + db.with(regionalSalesWith).select().from(regionalSalesWith).where(like(regionalSalesWith.totalSales, 'abc')); }