Skip to main content

Class: WhereClause<T>

Defined in: src/query/WhereClause.ts:87

Fluent builder for constructing SQL WHERE filter conditions.

Provides type-safe comparison operators, pattern matching, range queries, nested grouped expressions, JSON path inspection, and full-text search.

Type Parameters​

Type ParameterDefault type
Tany

Constructors​

Constructor​

new WhereClause<T>(): WhereClause<T>

Returns​

WhereClause<T>

Methods​

and()​

and(): this

Defined in: src/query/WhereClause.ts:97

Sets the conjunction operator for the next condition to AND (the default).

Returns​

this

this instance for method chaining.

Usecase​

Explicitly combine conditions with logical AND.


or()​

or(): this

Defined in: src/query/WhereClause.ts:112

Sets the conjunction operator for the next condition to OR.

Returns​

this

this instance for method chaining.

Usecase​

Combine conditions where at least one must evaluate to true.

Example​

query.where(w => w.eq('role', 'admin').or().eq('role', 'manager'));

eq()​

Call Signature​

eq<V>(selector, value): this

Defined in: src/query/WhereClause.ts:129

Adds an equality condition (column = value).

Type Parameters​
Type Parameter
V
Parameters​
ParameterTypeDescription
selector(entity) => VProperty selector function or column name.
valueVExpected value.
Returns​

this

this instance for method chaining.

Usecase​

Filter records where a property exactly matches a specified value.

Example​
w.eq(u => u.status, 'active')

Call Signature​

eq<K>(column, value): this

Defined in: src/query/WhereClause.ts:130

Adds an equality condition (column = value).

Type Parameters​
Type Parameter
K extends string
Parameters​
ParameterTypeDescription
columnK-
valueT[K]Expected value.
Returns​

this

this instance for method chaining.

Usecase​

Filter records where a property exactly matches a specified value.

Example​
w.eq(u => u.status, 'active')

Call Signature​

eq(column, value): this

Defined in: src/query/WhereClause.ts:131

Adds an equality condition (column = value).

Parameters​
ParameterTypeDescription
columnstring & object-
valueunknownExpected value.
Returns​

this

this instance for method chaining.

Usecase​

Filter records where a property exactly matches a specified value.

Example​
w.eq(u => u.status, 'active')

ne()​

Call Signature​

ne<V>(selector, value): this

Defined in: src/query/WhereClause.ts:148

Adds an inequality condition (column <> value).

Type Parameters​
Type Parameter
V
Parameters​
ParameterTypeDescription
selector(entity) => VProperty selector function or column name.
valueVValue to exclude.
Returns​

this

this instance for method chaining.

Usecase​

Filter out records matching an undesirable value.

Example​
w.ne('status', 'banned')

Call Signature​

ne<K>(column, value): this

Defined in: src/query/WhereClause.ts:149

Adds an inequality condition (column <> value).

Type Parameters​
Type Parameter
K extends string
Parameters​
ParameterTypeDescription
columnK-
valueT[K]Value to exclude.
Returns​

this

this instance for method chaining.

Usecase​

Filter out records matching an undesirable value.

Example​
w.ne('status', 'banned')

Call Signature​

ne(column, value): this

Defined in: src/query/WhereClause.ts:150

Adds an inequality condition (column <> value).

Parameters​
ParameterTypeDescription
columnstring & object-
valueunknownValue to exclude.
Returns​

this

this instance for method chaining.

Usecase​

Filter out records matching an undesirable value.

Example​
w.ne('status', 'banned')

gt()​

Call Signature​

gt<V>(selector, value): this

Defined in: src/query/WhereClause.ts:163

Adds a greater-than comparison (column > value).

Type Parameters​
Type Parameter
V
Parameters​
ParameterTypeDescription
selector(entity) => VProperty selector function or column name.
valueVThreshold value.
Returns​

this

this instance for method chaining.

Usecase​

Numeric thresholds, date cutoffs, or price minimums.

Call Signature​

gt<K>(column, value): this

Defined in: src/query/WhereClause.ts:164

Adds a greater-than comparison (column > value).

Type Parameters​
Type Parameter
K extends string
Parameters​
ParameterTypeDescription
columnK-
valueT[K]Threshold value.
Returns​

this

this instance for method chaining.

Usecase​

Numeric thresholds, date cutoffs, or price minimums.

Call Signature​

gt(column, value): this

Defined in: src/query/WhereClause.ts:165

Adds a greater-than comparison (column > value).

Parameters​
ParameterTypeDescription
columnstring & object-
valueunknownThreshold value.
Returns​

this

this instance for method chaining.

Usecase​

Numeric thresholds, date cutoffs, or price minimums.


gte()​

Call Signature​

gte<V>(selector, value): this

Defined in: src/query/WhereClause.ts:178

Adds a greater-than-or-equal comparison (column >= value).

Type Parameters​
Type Parameter
V
Parameters​
ParameterTypeDescription
selector(entity) => VProperty selector function or column name.
valueVMinimum inclusive value.
Returns​

this

this instance for method chaining.

Usecase​

Inclusive lower bounds on numbers and dates.

Call Signature​

gte<K>(column, value): this

Defined in: src/query/WhereClause.ts:179

Adds a greater-than-or-equal comparison (column >= value).

Type Parameters​
Type Parameter
K extends string
Parameters​
ParameterTypeDescription
columnK-
valueT[K]Minimum inclusive value.
Returns​

this

this instance for method chaining.

Usecase​

Inclusive lower bounds on numbers and dates.

Call Signature​

gte(column, value): this

Defined in: src/query/WhereClause.ts:180

Adds a greater-than-or-equal comparison (column >= value).

Parameters​
ParameterTypeDescription
columnstring & object-
valueunknownMinimum inclusive value.
Returns​

this

this instance for method chaining.

Usecase​

Inclusive lower bounds on numbers and dates.


lt()​

Call Signature​

lt<V>(selector, value): this

Defined in: src/query/WhereClause.ts:193

Adds a less-than comparison (column < value).

Type Parameters​
Type Parameter
V
Parameters​
ParameterTypeDescription
selector(entity) => VProperty selector function or column name.
valueVThreshold value.
Returns​

this

this instance for method chaining.

Usecase​

Upper bounds, maximum limits, or dates strictly prior to cutoff.

Call Signature​

lt<K>(column, value): this

Defined in: src/query/WhereClause.ts:194

Adds a less-than comparison (column < value).

Type Parameters​
Type Parameter
K extends string
Parameters​
ParameterTypeDescription
columnK-
valueT[K]Threshold value.
Returns​

this

this instance for method chaining.

Usecase​

Upper bounds, maximum limits, or dates strictly prior to cutoff.

Call Signature​

lt(column, value): this

Defined in: src/query/WhereClause.ts:195

Adds a less-than comparison (column < value).

Parameters​
ParameterTypeDescription
columnstring & object-
valueunknownThreshold value.
Returns​

this

this instance for method chaining.

Usecase​

Upper bounds, maximum limits, or dates strictly prior to cutoff.


lte()​

Call Signature​

lte<V>(selector, value): this

Defined in: src/query/WhereClause.ts:208

Adds a less-than-or-equal comparison (column <= value).

Type Parameters​
Type Parameter
V
Parameters​
ParameterTypeDescription
selector(entity) => VProperty selector function or column name.
valueVMaximum inclusive value.
Returns​

this

this instance for method chaining.

Usecase​

Inclusive upper bounds on numbers and dates.

Call Signature​

lte<K>(column, value): this

Defined in: src/query/WhereClause.ts:209

Adds a less-than-or-equal comparison (column <= value).

Type Parameters​
Type Parameter
K extends string
Parameters​
ParameterTypeDescription
columnK-
valueT[K]Maximum inclusive value.
Returns​

this

this instance for method chaining.

Usecase​

Inclusive upper bounds on numbers and dates.

Call Signature​

lte(column, value): this

Defined in: src/query/WhereClause.ts:210

Adds a less-than-or-equal comparison (column <= value).

Parameters​
ParameterTypeDescription
columnstring & object-
valueunknownMaximum inclusive value.
Returns​

this

this instance for method chaining.

Usecase​

Inclusive upper bounds on numbers and dates.


like()​

Call Signature​

like(selector, pattern): this

Defined in: src/query/WhereClause.ts:227

Adds a pattern-matching condition (column LIKE pattern).

Parameters​
ParameterTypeDescription
selector(entity) => unknownProperty selector function or column name.
patternstringSQL wildcard pattern (e.g. '%example.com').
Returns​

this

this instance for method chaining.

Usecase​

Substring search or prefix/suffix wildcard matching with % and _.

Example​
w.like('email', '%@company.org')

Call Signature​

like(column, pattern): this

Defined in: src/query/WhereClause.ts:228

Adds a pattern-matching condition (column LIKE pattern).

Parameters​
ParameterTypeDescription
columnColumnKey<T>-
patternstringSQL wildcard pattern (e.g. '%example.com').
Returns​

this

this instance for method chaining.

Usecase​

Substring search or prefix/suffix wildcard matching with % and _.

Example​
w.like('email', '%@company.org')

notLike()​

Call Signature​

notLike(selector, pattern): this

Defined in: src/query/WhereClause.ts:241

Adds a negative pattern-matching condition (column NOT LIKE pattern).

Parameters​
ParameterTypeDescription
selector(entity) => unknownProperty selector function or column name.
patternstringSQL wildcard pattern.
Returns​

this

this instance for method chaining.

Usecase​

Exclude records matching a specific wildcard pattern.

Call Signature​

notLike(column, pattern): this

Defined in: src/query/WhereClause.ts:242

Adds a negative pattern-matching condition (column NOT LIKE pattern).

Parameters​
ParameterTypeDescription
columnColumnKey<T>-
patternstringSQL wildcard pattern.
Returns​

this

this instance for method chaining.

Usecase​

Exclude records matching a specific wildcard pattern.


in()​

Call Signature​

in<V>(selector, values): this

Defined in: src/query/WhereClause.ts:259

Adds a set inclusion test (column IN (...)).

Type Parameters​
Type Parameter
V
Parameters​
ParameterTypeDescription
selector(entity) => VProperty selector function or column name.
valuesV[]Array of matching values.
Returns​

this

this instance for method chaining.

Usecase​

Filter records whose column matches any element in an array of candidate values.

Example​
w.in('status', ['pending', 'processing', 'review'])

Call Signature​

in<K>(column, values): this

Defined in: src/query/WhereClause.ts:260

Adds a set inclusion test (column IN (...)).

Type Parameters​
Type Parameter
K extends string
Parameters​
ParameterTypeDescription
columnK-
valuesT[K][]Array of matching values.
Returns​

this

this instance for method chaining.

Usecase​

Filter records whose column matches any element in an array of candidate values.

Example​
w.in('status', ['pending', 'processing', 'review'])

Call Signature​

in(column, values): this

Defined in: src/query/WhereClause.ts:261

Adds a set inclusion test (column IN (...)).

Parameters​
ParameterTypeDescription
columnstring & object-
valuesunknown[]Array of matching values.
Returns​

this

this instance for method chaining.

Usecase​

Filter records whose column matches any element in an array of candidate values.

Example​
w.in('status', ['pending', 'processing', 'review'])

notIn()​

Call Signature​

notIn<V>(selector, values): this

Defined in: src/query/WhereClause.ts:274

Adds a set exclusion test (column NOT IN (...)).

Type Parameters​
Type Parameter
V
Parameters​
ParameterTypeDescription
selector(entity) => VProperty selector function or column name.
valuesV[]Array of excluded values.
Returns​

this

this instance for method chaining.

Usecase​

Exclude records whose column matches any element in an array of values.

Call Signature​

notIn<K>(column, values): this

Defined in: src/query/WhereClause.ts:275

Adds a set exclusion test (column NOT IN (...)).

Type Parameters​
Type Parameter
K extends string
Parameters​
ParameterTypeDescription
columnK-
valuesT[K][]Array of excluded values.
Returns​

this

this instance for method chaining.

Usecase​

Exclude records whose column matches any element in an array of values.

Call Signature​

notIn(column, values): this

Defined in: src/query/WhereClause.ts:276

Adds a set exclusion test (column NOT IN (...)).

Parameters​
ParameterTypeDescription
columnstring & object-
valuesunknown[]Array of excluded values.
Returns​

this

this instance for method chaining.

Usecase​

Exclude records whose column matches any element in an array of values.


isNull()​

Call Signature​

isNull(selector): this

Defined in: src/query/WhereClause.ts:288

Adds an IS NULL condition.

Parameters​
ParameterTypeDescription
selector(entity) => unknownProperty selector function or column name.
Returns​

this

this instance for method chaining.

Usecase​

Filter records where a nullable column has no assigned value.

Call Signature​

isNull(column): this

Defined in: src/query/WhereClause.ts:289

Adds an IS NULL condition.

Parameters​
ParameterType
columnColumnKey<T>
Returns​

this

this instance for method chaining.

Usecase​

Filter records where a nullable column has no assigned value.


isNotNull()​

Call Signature​

isNotNull(selector): this

Defined in: src/query/WhereClause.ts:301

Adds an IS NOT NULL condition.

Parameters​
ParameterTypeDescription
selector(entity) => unknownProperty selector function or column name.
Returns​

this

this instance for method chaining.

Usecase​

Filter records where a nullable column contains a value.

Call Signature​

isNotNull(column): this

Defined in: src/query/WhereClause.ts:302

Adds an IS NOT NULL condition.

Parameters​
ParameterType
columnColumnKey<T>
Returns​

this

this instance for method chaining.

Usecase​

Filter records where a nullable column contains a value.


between()​

Call Signature​

between<V>(selector, start, end): this

Defined in: src/query/WhereClause.ts:320

Adds an inclusive range condition (column BETWEEN start AND end).

Type Parameters​
Type Parameter
V
Parameters​
ParameterTypeDescription
selector(entity) => VProperty selector function or column name.
startVLower range boundary (inclusive).
endVUpper range boundary (inclusive).
Returns​

this

this instance for method chaining.

Usecase​

Filter date ranges or numeric ranges cleanly without separate >= and <= calls.

Example​
w.between('price', 10, 50)

Call Signature​

between<K>(column, start, end): this

Defined in: src/query/WhereClause.ts:321

Adds an inclusive range condition (column BETWEEN start AND end).

Type Parameters​
Type Parameter
K extends string
Parameters​
ParameterTypeDescription
columnK-
startT[K]Lower range boundary (inclusive).
endT[K]Upper range boundary (inclusive).
Returns​

this

this instance for method chaining.

Usecase​

Filter date ranges or numeric ranges cleanly without separate >= and <= calls.

Example​
w.between('price', 10, 50)

Call Signature​

between(column, start, end): this

Defined in: src/query/WhereClause.ts:322

Adds an inclusive range condition (column BETWEEN start AND end).

Parameters​
ParameterTypeDescription
columnstring & object-
startunknownLower range boundary (inclusive).
endunknownUpper range boundary (inclusive).
Returns​

this

this instance for method chaining.

Usecase​

Filter date ranges or numeric ranges cleanly without separate >= and <= calls.

Example​
w.between('price', 10, 50)

group()​

group(builderFn): this

Defined in: src/query/WhereClause.ts:338

Groups a set of conditions enclosed in parentheses (cond1 OR cond2).

Parameters​

ParameterTypeDescription
builderFn(subClause) => voidCallback receiving a sub-WhereClause builder.

Returns​

this

this instance for method chaining.

Usecase​

Control operator precedence when mixing AND with OR logic.

Example​

w.eq('isActive', true).and().group(g => g.eq('tier', 'gold').or().gt('points', 1000));

whereJson()​

whereJson(column, path, operatorOrValue, value?): this

Defined in: src/query/WhereClause.ts:361

Adds a filter inside a JSON/JSONB document property.

Parameters​

ParameterTypeDescription
columnColumnKey<T> | ((entity) => unknown)Property containing the JSON payload.
pathstringDot-separated path inside the JSON object (e.g. 'address.zip').
operatorOrValueunknownComparison operator (e.g. '=', '>') or target value when testing equality.
value?unknownTarget value if operator was supplied.

Returns​

this

this instance for method chaining.

Usecase​

Query nested attributes inside JSON columns with database dialect-specific operators.


json()​

json(column, path, operatorOrValue, value?): this

Defined in: src/query/WhereClause.ts:390

Shorthand alias for whereJson.

Parameters​

ParameterType
columnColumnKey<T> | ((entity) => unknown)
pathstring
operatorOrValueunknown
value?unknown

Returns​

this

Usecase​

Filter nested attributes inside JSON columns.


whereSearch()​

whereSearch(columns, query, options?): this

Defined in: src/query/WhereClause.ts:408

Adds native full-text search condition across multiple columns.

Parameters​

ParameterTypeDescription
columns(ColumnKey<T> | ((entity) => unknown))[]Columns or property selectors to search across.
querystringSearch keywords.
options?SearchOptionsFull-text options (search mode, language).

Returns​

this

this instance for method chaining.

Usecase​

Implement keyword search with database-native indexing across text fields.


search(columns, query, options?): this

Defined in: src/query/WhereClause.ts:431

Shorthand alias for whereSearch.

Parameters​

ParameterType
columns(ColumnKey<T> | ((entity) => unknown))[]
querystring
options?SearchOptions

Returns​

this

Usecase​

Full-text search across text columns.


raw()​

raw(sql, params?): this

Defined in: src/query/WhereClause.ts:447

Injects a raw SQL WHERE condition with parameterized values.

Parameters​

ParameterTypeDescription
sqlstringRaw SQL condition string.
params?unknown[]Optional parameter array.

Returns​

this

this instance for method chaining.

Usecase​

Vendor-specific functions, geospatial expressions, or math calculations.


exists()​

exists(subquery, joinPredicate?): this

Defined in: src/query/WhereClause.ts:468

Adds an SQL EXISTS (SELECT ...) subquery condition.

Parameters​

ParameterTypeDescription
subqueryanyQueryBuilder, Subquery instance, or SQL string.
joinPredicate?(outer, inner) => voidCallback defining join predicate between outer entity and subquery alias.

Returns​

this

this instance for method chaining.

Example​

w.exists(highValueCustomers, (order, hvc) => order.customerId.eq(hvc.id));

notExists()​

notExists(subquery, joinPredicate?): this

Defined in: src/query/WhereClause.ts:488

Adds an SQL NOT EXISTS (SELECT ...) subquery condition.

Parameters​

ParameterTypeDescription
subqueryanyQueryBuilder, Subquery instance, or SQL string.
joinPredicate?(outer, inner) => voidCallback defining join predicate between outer entity and subquery alias.

Returns​

this

this instance for method chaining.

Properties​

conditions​

readonly conditions: WhereCondition[] = []

Defined in: src/query/WhereClause.ts:88