Class

Condition

Condition(attr1, operator, comparison)

Constructor

# new Condition(attr1, operator, comparison)

A class that encapsulates query conditions with support for complex logical operations. This class allows for building and combining query conditions using logical operators (AND, OR, NOT) and comparison operators (equals, not equals, greater than, etc.).

Represents a logical condition for database queries

Parameters:
Name Type Description
attr1 string | Condition.<M>

The attribute name or a nested condition

operator Operator | GroupOperator

The operator to use for the condition

comparison any

The value to compare against or another condition

View Source query/Condition.ts, line 11

Example
// Create a simple condition
const nameCondition = Condition.attribute("name").eq("John");

// Create a complex condition
const complexCondition = Condition.attribute("age").gt(18)
  .and(Condition.attribute("status").eq("active"));

// Use the builder pattern
const userQuery = Condition.builder()
  .attribute("email").regexp(".*@example.com")
  .and(Condition.attribute("lastLogin").gt(new Date("2023-01-01")));

Methods

# and(condition) → {Condition.<M>}

Joins two conditions with an AND operator, requiring both to be true

Combines this condition with another using logical AND

Parameters:
Name Type Description
condition Condition.<M>

The condition to combine with this one

View Source query/Condition.ts, line 336

A new condition representing the AND operation

Condition.<M>

# hasErrors(…exceptions) → {ModelErrorDefinition|undefined}

Extends the base validation to ensure the condition is properly formed

Validates the condition and checks for errors

Parameters:
Name Type Attributes Description
exceptions Array.<string> <repeatable>

Fields to exclude from validation

View Source query/Condition.ts, line 360

Error definition if validation fails, undefined otherwise

ModelErrorDefinition | undefined

# not(val) → {Condition.<M>}

Excludes a value from the result by applying a NOT operator

Creates a negation condition

Parameters:
Name Type Description
val any

The value to negate

View Source query/Condition.ts, line 352

A new condition representing the NOT operation

Condition.<M>

# or(condition) → {Condition.<M>}

Joins two conditions with an OR operator, requiring at least one to be true

Combines this condition with another using logical OR

Parameters:
Name Type Description
condition Condition.<M>

The condition to combine with this one

View Source query/Condition.ts, line 344

A new condition representing the OR operation

Condition.<M>

# static and(condition1, condition2) → {Condition.<M>}

Static method that joins two conditions with an AND operator, requiring both to be true

Creates a new condition that combines two conditions with logical AND

Parameters:
Name Type Description
condition1 Condition.<M>

The first condition

condition2 Condition.<M>

The second condition

View Source query/Condition.ts, line 370

A new condition representing the AND operation

Condition.<M>

# static attr(attr) → {AttributeOption.<M>}

Shorthand method that initializes a condition builder with the specified attribute

Alias for the attribute method

Parameters:
Name Type Description
attr

The model attribute to build a condition for

View Source query/Condition.ts, line 410

A condition builder initialized with the attribute

AttributeOption.<M>

# static attribute(attr) → {AttributeOption.<M>}

Static method that initializes a condition builder with the specified attribute

Creates a condition builder for a specific model attribute

Parameters:
Name Type Description
attr

The model attribute to build a condition for

View Source query/Condition.ts, line 401

A condition builder initialized with the attribute

AttributeOption.<M>

# static builder() → {ConditionBuilderOption.<M>}

Factory method that returns a new instance of the condition builder

Creates a new condition builder

View Source query/Condition.ts, line 427

A new condition builder instance

ConditionBuilderOption.<M>

# static group(condition1, operator, condition2) → {Condition.<M>}

Private static method that combines two conditions using the specified group operator

Creates a new condition that groups two conditions with a specified operator

Parameters:
Name Type Description
condition1 Condition.<M>

The first condition

operator GroupOperator

The group operator to use (AND, OR)

condition2 Condition.<M>

The second condition

View Source query/Condition.ts, line 151

A new condition representing the grouped operation

Condition.<M>

# static or(condition1, condition2) → {Condition.<M>}

Static method that joins two conditions with an OR operator, requiring at least one to be true

Creates a new condition that combines two conditions with logical OR

Parameters:
Name Type Description
condition1 Condition.<M>

The first condition

condition2 Condition.<M>

The second condition

View Source query/Condition.ts, line 380

A new condition representing the OR operation

Condition.<M>