Match a literal value list
Filter records against a known set of IDs, statuses, categories, or other values supplied by application code.
Drizzle ORM · Function
inArray creates a Drizzle filter that checks whether a column matches one of several values. It accepts either an array or a subquery and produces an SQL IN condition.
Use inArray in a where clause to test whether a column matches one of several values. The second argument may be an array of values or a subquery selecting compatible values, and Drizzle emits the corresponding SQL IN condition.
inArray(column, values)| Name | Type | Description |
|---|---|---|
column | Column | The table column whose value is checked for membership. |
values | Array | Select query | An array of compatible values or a subquery selecting compatible values. |
A Drizzle SQL condition representing column membership in an array or subquery.
import { inArray } from "drizzle-orm";
import { users } from "./schema";
const ids = [1, 2, 3];
const matchingUsers = await db
.select()
.from(users)
.where(inArray(users.id, ids));Builds a query that selects users whose IDs occur in the supplied array.
Filter records against a known set of IDs, statuses, categories, or other values supplied by application code.
Filter one table using values selected from another query.
inArray creates a filter for membership in a collection of values. For example, applying it to a column and [1, 2, 3, 4] produces an SQL IN predicate.
Follow-up: How can the candidate use a query instead of a literal list? Pass a subquery as the second argument; Drizzle produces an IN subquery condition.
Its first argument is the column being tested, and its second argument is either an array of candidate values or a selecting query. The selected values must be suitable for comparison with that column.
Follow-up: What SQL shape does a subquery form take? It becomes column IN (SELECT ...), with the selected expression supplying the comparison values.
The function is imported from drizzle-orm and is typically passed to where on a select, update, or delete query. This lets the database perform membership filtering rather than requiring separate application-side checks.
Follow-up: How would you filter using values returned from another table? Build a select query for the relevant column and pass that query as the second inArray argument.
notInArrayeqandor