Skip to main content
where is a method that specifies conditions to filter query results. It supports various operators and condition combinations, enabling type-safe filtering.

Basic Usage

Simple Equality Condition

Comparison Operators

Supported Operators:
  • = - Equal (default)
  • != - Not equal
  • > - Greater than
  • >= - Greater than or equal
  • < - Less than
  • <= - Less than or equal
  • like - Pattern matching
  • not like - Pattern mismatch
  • ilike - Case-insensitive pattern matching (PostgreSQL)
  • not ilike - Case-insensitive pattern mismatch (PostgreSQL)

Object-Style Conditions

You can specify multiple AND conditions as an object.

NULL Handling

IS NULL

IS NOT NULL

Pattern Matching (LIKE)

Partial Matching

NOT LIKE

ILIKE (Case-Insensitive, PostgreSQL)

Performs case-insensitive pattern matching in PostgreSQL.

NOT ILIKE (PostgreSQL)

ilike and not ilike are PostgreSQL’s case-insensitive pattern matching operators.

whereIn / whereNotIn

One of Multiple Values

Empty Array Handling

Complex Condition Groups

whereGroup (AND Group)

Creates conditions wrapped in parentheses.

orWhereGroup (OR Group)

Nested Groups

whereMatch (MySQL)

Uses MySQL’s FULLTEXT index.
To use whereMatch, the column must have a FULLTEXT index.

whereTsSearch (PostgreSQL)

Uses PostgreSQL’s tsvector.
Options:

whereSearch (PGroonga)

Full-text search using the PGroonga extension.
PGroonga search must use the same column configuration as the index to be used.

whereFuzzy (pg_trgm)

Fuzzy string matching using PostgreSQL’s pg_trgm extension. Based on trigrams, it is tolerant of typos. Combined with generated columns and GIN indexes, it is effective for multi-column search.
Specifying operators:
Operator comparison:
whereFuzzy requires the pg_trgm extension. Install it with CREATE EXTENSION IF NOT EXISTS pg_trgm. Creating a GIN index (gin_trgm_ops) significantly improves performance.

Raw SQL Conditions

whereRaw

You can write complex SQL conditions directly.
Always use parameter binding to prevent SQL injection.

Real-World Examples

Condition Chaining

All where methods are chainable and are connected with AND by default.

OR Conditions

orWhere within WhereGroup

There is no orWhere at the top level. Use OR conditions within whereGroup or orWhereGroup.

Type Safety

WHERE conditions are validated type-safely.

Performance Optimization

1. Utilizing Indexes

2. LIKE/ILIKE Patterns

In PostgreSQL, ilike is convenient for case-insensitive search, but it can affect performance on large datasets. Consider using citext type or pg_trgm extension indexes for such cases.

3. IN vs Multiple ORs

Cautions

1. NULL Handling

2. Empty Arrays

3. Raw SQL Injection

4. Condition Order

Next Steps

select

Select fields to retrieve

join

Join tables

order-by

Sort results

limit

Limit number of results