ν•„ν„° 및 쑰건 μ—°μ‚°μž

λͺ¨λ“  λ°μ΄ν„°λ² μ΄μŠ€ νŠΉμ • ν•„ν„° 및 쑰건 μ—°μ‚°μžλ₯Ό 기본적으둜 μ§€μ›ν•©λ‹ˆλ‹€.

drizzle-ormμ—μ„œ λͺ¨λ“  ν•„ν„° 및 쑰건 μ—°μ‚°μžλ₯Ό κ°€μ Έμ˜¬ 수 μžˆμŠ΅λ‹ˆλ‹€:

import { eq, ne, gt, gte, ... } from "drizzle-orm";

eq

PostgreSQL
MySQL
SQLite
SingleStore

값이 nκ³Ό κ°™μŒ

import { eq } from "drizzle-orm";

db.select().from(table).where(eq(table.column, 5));
SELECT * FROM table WHERE table.column = 5
import { eq } from "drizzle-orm";

db.select().from(table).where(eq(table.column1, table.column2));
SELECT * FROM table WHERE table.column1 = table.column2

ne

PostgreSQL
MySQL
SQLite
SingleStore

값이 nκ³Ό κ°™μ§€ μ•ŠμŒ

import { ne } from "drizzle-orm";

db.select().from(table).where(ne(table.column, 5));
SELECT * FROM table WHERE table.column <> 5
import { ne } from "drizzle-orm";

db.select().from(table).where(ne(table.column1, table.column2));
SELECT * FROM table WHERE table.column1 <> table.column2

---

gt

PostgreSQL
MySQL
SQLite
SingleStore

값이 n보닀 큼

import { gt } from "drizzle-orm";

db.select().from(table).where(gt(table.column, 5));
SELECT * FROM table WHERE table.column > 5
import { gt } from "drizzle-orm";

db.select().from(table).where(gt(table.column1, table.column2));
SELECT * FROM table WHERE table.column1 > table.column2

gte

PostgreSQL
MySQL
SQLite
SingleStore

값이 n보닀 ν¬κ±°λ‚˜ κ°™μŒ

import { gte } from "drizzle-orm";

db.select().from(table).where(gte(table.column, 5));
SELECT * FROM table WHERE table.column >= 5
import { gte } from "drizzle-orm";

db.select().from(table).where(gte(table.column1, table.column2));
SELECT * FROM table WHERE table.column1 >= table.column2

lt

PostgreSQL
MySQL
SQLite
SingleStore

값이 n보닀 μž‘μŒ

import { lt } from "drizzle-orm";

db.select().from(table).where(lt(table.column, 5));
SELECT * FROM table WHERE table.column < 5
import { lt } from "drizzle-orm";

db.select().from(table).where(lt(table.column1, table.column2));
SELECT * FROM table WHERE table.column1 < table.column2

lte

PostgreSQL
MySQL
SQLite
SingleStore

값이 n보닀 μž‘κ±°λ‚˜ κ°™μŒ

import { lte } from "drizzle-orm";

db.select().from(table).where(lte(table.column, 5));
SELECT * FROM table WHERE table.column <= 5
import { lte } from "drizzle-orm";

db.select().from(table).where(lte(table.column1, table.column2));
SELECT * FROM table WHERE table.column1 <= table.column2

---

exists

PostgreSQL
MySQL
SQLite
SingleStore

값이 μ‘΄μž¬ν•¨

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

PostgreSQL
MySQL
SQLite
SingleStore

값이 nullμž„

import { isNull } from "drizzle-orm";

db.select().from(table).where(isNull(table.column));
SELECT * FROM table WHERE table.column IS NULL

isNotNull

PostgreSQL
MySQL
SQLite
SingleStore

값이 null이 μ•„λ‹˜

import { isNotNull } from "drizzle-orm";

db.select().from(table).where(isNotNull(table.column));
SELECT * FROM table WHERE table.column IS NOT NULL

---

inArray

PostgreSQL
MySQL
SQLite
SingleStore

값이 λ°°μ—΄μ˜ κ°’ 쀑 ν•˜λ‚˜μž„

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

PostgreSQL
MySQL
SQLite
SingleStore

값이 λ°°μ—΄μ˜ κ°’ 쀑 μ–΄λŠ 것도 μ•„λ‹˜

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

PostgreSQL
MySQL
SQLite
SingleStore

값이 두 κ°’ 사이에 있음

import { between } from "drizzle-orm";

db.select().from(table).where(between(table.column, 2, 7));
SELECT * FROM table WHERE table.column BETWEEN 2 AND 7

notBetween

PostgreSQL
MySQL
SQLite
SingleStore

값이 두 κ°’ 사이에 μžˆμ§€ μ•ŠμŒ

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

PostgreSQL
MySQL
SQLite
SingleStore

값이 λ‹€λ₯Έ κ°’κ³Ό μœ μ‚¬ν•¨, λŒ€μ†Œλ¬Έμž ꡬ뢄

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

PostgreSQL
MySQL
SQLite
SingleStore

값이 λ‹€λ₯Έ κ°’κ³Ό μœ μ‚¬ν•¨, λŒ€μ†Œλ¬Έμž ꡬ뢄 μ•ˆ 함

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

PostgreSQL
MySQL
SQLite
SingleStore

값이 λ‹€λ₯Έ κ°’κ³Ό μœ μ‚¬ν•˜μ§€ μ•ŠμŒ, λŒ€μ†Œλ¬Έμž ꡬ뢄 μ•ˆ 함

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

PostgreSQL
MySQL
SQLite
SingleStore

λͺ¨λ“  쑰건이 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

PostgreSQL
MySQL
SQLite
SingleStore

λͺ¨λ“  쑰건이 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

PostgreSQL
MySQL
SQLite
SingleStore

ν•˜λ‚˜ μ΄μƒμ˜ 쑰건이 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

PostgreSQL
MySQL
SQLite
SingleStore

μ»¬λŸΌμ΄λ‚˜ ν‘œν˜„μ‹μ΄ 두 번째 인자둜 μ „λ‹¬λœ λͺ©λ‘μ˜ λͺ¨λ“  μš”μ†Œλ₯Ό ν¬ν•¨ν•˜λŠ”μ§€ ν…ŒμŠ€νŠΈ

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

PostgreSQL
MySQL
SQLite
SingleStore

두 번째 인자둜 μ „λ‹¬λœ λͺ©λ‘μ΄ μ»¬λŸΌμ΄λ‚˜ ν‘œν˜„μ‹μ˜ λͺ¨λ“  μš”μ†Œλ₯Ό ν¬ν•¨ν•˜λŠ”μ§€ ν…ŒμŠ€νŠΈ

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

PostgreSQL
MySQL
SQLite
SingleStore

μ»¬λŸΌμ΄λ‚˜ ν‘œν˜„μ‹μ΄ 두 번째 인자둜 μ „λ‹¬λœ λͺ©λ‘μ˜ μš”μ†Œ 쀑 ν•˜λ‚˜λΌλ„ ν¬ν•¨ν•˜λŠ”μ§€ ν…ŒμŠ€νŠΈ

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}