# 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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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
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 |
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 |
A new condition representing the OR operation
Condition.<M>