νν° λ° μ‘°κ±΄ μ°μ°μ
λͺ¨λ λ°μ΄ν°λ² μ΄μ€ νΉμ νν° λ° μ‘°κ±΄ μ°μ°μλ₯Ό κΈ°λ³Έμ μΌλ‘ μ§μν©λλ€.
drizzle-ormμμ λͺ¨λ νν° λ° μ‘°κ±΄ μ°μ°μλ₯Ό κ°μ Έμ¬ μ μμ΅λλ€:
import { eq, ne, gt, gte, ... } from "drizzle-orm";eq
κ°μ΄ nκ³Ό κ°μ
import { eq } from "drizzle-orm";
db.select().from(table).where(eq(table.column, 5));SELECT * FROM table WHERE table.column = 5import { eq } from "drizzle-orm";
db.select().from(table).where(eq(table.column1, table.column2));SELECT * FROM table WHERE table.column1 = table.column2ne
κ°μ΄ nκ³Ό κ°μ§ μμ
import { ne } from "drizzle-orm";
db.select().from(table).where(ne(table.column, 5));SELECT * FROM table WHERE table.column <> 5import { ne } from "drizzle-orm";
db.select().from(table).where(ne(table.column1, table.column2));SELECT * FROM table WHERE table.column1 <> table.column2---
gt
κ°μ΄ nλ³΄λ€ νΌ
import { gt } from "drizzle-orm";
db.select().from(table).where(gt(table.column, 5));SELECT * FROM table WHERE table.column > 5import { gt } from "drizzle-orm";
db.select().from(table).where(gt(table.column1, table.column2));SELECT * FROM table WHERE table.column1 > table.column2gte
κ°μ΄ nλ³΄λ€ ν¬κ±°λ κ°μ
import { gte } from "drizzle-orm";
db.select().from(table).where(gte(table.column, 5));SELECT * FROM table WHERE table.column >= 5import { gte } from "drizzle-orm";
db.select().from(table).where(gte(table.column1, table.column2));SELECT * FROM table WHERE table.column1 >= table.column2lt
κ°μ΄ nλ³΄λ€ μμ
import { lt } from "drizzle-orm";
db.select().from(table).where(lt(table.column, 5));SELECT * FROM table WHERE table.column < 5import { lt } from "drizzle-orm";
db.select().from(table).where(lt(table.column1, table.column2));SELECT * FROM table WHERE table.column1 < table.column2lte
κ°μ΄ nλ³΄λ€ μκ±°λ κ°μ
import { lte } from "drizzle-orm";
db.select().from(table).where(lte(table.column, 5));SELECT * FROM table WHERE table.column <= 5import { lte } from "drizzle-orm";
db.select().from(table).where(lte(table.column1, table.column2));SELECT * FROM table WHERE table.column1 <= table.column2---
exists
κ°μ΄ μ‘΄μ¬ν¨
import { exists } from "drizzle-orm";
const query = db.select().from(table2)
db.select().from(table).where(exists(query));SELECT * FROM table WHERE EXISTS (SELECT * from table2)notExists
import { notExists } from "drizzle-orm";
const query = db.select().from(table2)
db.select().from(table).where(notExists(query));SELECT * FROM table WHERE NOT EXISTS (SELECT * from table2)isNull
κ°μ΄ nullμ
import { isNull } from "drizzle-orm";
db.select().from(table).where(isNull(table.column));SELECT * FROM table WHERE table.column IS NULLisNotNull
κ°μ΄ nullμ΄ μλ
import { isNotNull } from "drizzle-orm";
db.select().from(table).where(isNotNull(table.column));SELECT * FROM table WHERE table.column IS NOT NULL---
inArray
κ°μ΄ λ°°μ΄μ κ° μ€ νλμ
import { inArray } from "drizzle-orm";
db.select().from(table).where(inArray(table.column, [1, 2, 3, 4]));SELECT * FROM table WHERE table.column in (1, 2, 3, 4)import { inArray } from "drizzle-orm";
const query = db.select({ data: table2.column }).from(table2);
db.select().from(table).where(inArray(table.column, query));SELECT * FROM table WHERE table.column IN (SELECT table2.column FROM table2)notInArray
κ°μ΄ λ°°μ΄μ κ° μ€ μ΄λ κ²λ μλ
import { notInArray } from "drizzle-orm";
db.select().from(table).where(notInArray(table.column, [1, 2, 3, 4]));SELECT * FROM table WHERE table.column NOT in (1, 2, 3, 4)import { notInArray } from "drizzle-orm";
const query = db.select({ data: table2.column }).from(table2);
db.select().from(table).where(notInArray(table.column, query));SELECT * FROM table WHERE table.column NOT IN (SELECT table2.column FROM table2)---
between
κ°μ΄ λ κ° μ¬μ΄μ μμ
import { between } from "drizzle-orm";
db.select().from(table).where(between(table.column, 2, 7));SELECT * FROM table WHERE table.column BETWEEN 2 AND 7notBetween
κ°μ΄ λ κ° μ¬μ΄μ μμ§ μμ
import { notBetween } from "drizzle-orm";
db.select().from(table).where(notBetween(table.column, 2, 7));SELECT * FROM table WHERE table.column NOT BETWEEN 2 AND 7---
like
κ°μ΄ λ€λ₯Έ κ°κ³Ό μ μ¬ν¨, λμλ¬Έμ ꡬλΆ
import { like } from "drizzle-orm";
db.select().from(table).where(like(table.column, "%llo wor%"));SELECT * FROM table WHERE table.column LIKE '%llo wor%'ilike
κ°μ΄ λ€λ₯Έ κ°κ³Ό μ μ¬ν¨, λμλ¬Έμ κ΅¬λΆ μ ν¨
import { ilike } from "drizzle-orm";
db.select().from(table).where(ilike(table.column, "%llo wor%"));SELECT * FROM table WHERE table.column ILIKE '%llo wor%'notIlike
κ°μ΄ λ€λ₯Έ κ°κ³Ό μ μ¬νμ§ μμ, λμλ¬Έμ κ΅¬λΆ μ ν¨
import { notIlike } from "drizzle-orm";
db.select().from(table).where(notIlike(table.column, "%llo wor%"));SELECT * FROM table WHERE table.column NOT ILIKE '%llo wor%'---
not
λͺ¨λ μ‘°κ±΄μ΄ falseλ₯Ό λ°νν΄μΌ ν¨
import { eq, not } from "drizzle-orm";
db.select().from(table).where(not(eq(table.column, 5)));SELECT * FROM table WHERE NOT (table.column = 5)and
λͺ¨λ μ‘°κ±΄μ΄ trueλ₯Ό λ°νν΄μΌ ν¨
import { gt, lt, and } from "drizzle-orm";
db.select().from(table).where(and(gt(table.column, 5), lt(table.column, 7)));SELECT * FROM table WHERE (table.column > 5 AND table.column < 7)or
νλ μ΄μμ μ‘°κ±΄μ΄ trueλ₯Ό λ°νν΄μΌ ν¨
import { gt, lt, or } from "drizzle-orm";
db.select().from(table).where(or(gt(table.column, 5), lt(table.column, 7)));SELECT * FROM table WHERE (table.column > 5 OR table.column < 7)---
arrayContains
컬λΌμ΄λ ννμμ΄ λ λ²μ§Έ μΈμλ‘ μ λ¬λ λͺ©λ‘μ λͺ¨λ μμλ₯Ό ν¬ν¨νλμ§ ν μ€νΈ
import { arrayContains } from "drizzle-orm";
const contains = await db.select({ id: posts.id }).from(posts)
.where(arrayContains(posts.tags, ['Typescript', 'ORM']));
const withSubQuery = await db.select({ id: posts.id }).from(posts)
.where(arrayContains(
posts.tags,
db.select({ tags: posts.tags }).from(posts).where(eq(posts.id, 1)),
));select "id" from "posts" where "posts"."tags" @> {Typescript,ORM};
select "id" from "posts" where "posts"."tags" @> (select "tags" from "posts" where "posts"."id" = 1);arrayContained
λ λ²μ§Έ μΈμλ‘ μ λ¬λ λͺ©λ‘μ΄ μ»¬λΌμ΄λ ννμμ λͺ¨λ μμλ₯Ό ν¬ν¨νλμ§ ν μ€νΈ
import { arrayContained } from "drizzle-orm";
const contained = await db.select({ id: posts.id }).from(posts)
.where(arrayContained(posts.tags, ['Typescript', 'ORM']));select "id" from "posts" where "posts"."tags" <@ {Typescript,ORM};arrayOverlaps
컬λΌμ΄λ ννμμ΄ λ λ²μ§Έ μΈμλ‘ μ λ¬λ λͺ©λ‘μ μμ μ€ νλλΌλ ν¬ν¨νλμ§ ν μ€νΈ
import { arrayOverlaps } from "drizzle-orm";
const overlaps = await db.select({ id: posts.id }).from(posts)
.where(arrayOverlaps(posts.tags, ['Typescript', 'ORM']));select "id" from "posts" where "posts"."tags" && {Typescript,ORM}