ascetic_ddd.faker.domain.query.operators

Query operators for MongoDB-like query syntax.

Operators: - $eq: equality check - $ne: not equal - $gt, $gte, $lt, $lte: comparison operators - $in: value in list - $is_null: null check - $rel: constraints for related aggregate - $or: logical OR of expressions

Multiple operators at same level are implicit AND:

{‘$gt’: 5, ‘$lt’: 10} -> AndOperator((ComparisonOperator(‘$gt’, 5), ComparisonOperator(‘$lt’, 10)))

Examples

{‘$eq’: 27} # scalar value {‘$ne’: ‘deleted’} # not equal {‘$gt’: 5, ‘$lt’: 10} # range (implicit AND) {‘$in’: [‘active’, ‘pending’]} # value in list {‘$is_null’: True} # null check {‘$is_null’: False} # not null check {‘tenant_id’: {‘$eq’: 15}, ‘local_id’: {‘$eq’: 27}} # composite PK {‘$rel’: {‘is_active’: {‘$eq’: True}}} # related aggregate criteria {‘$or’: [{‘status’: {‘$eq’: ‘active’}}, {‘status’: {‘$eq’: ‘pending’}}]}

Classes

AndOperator(operands)

Implicit AND of operators at the same level.

ComparisonOperator(op, value)

Comparison operator: {'$ne': value}, {'$gt': value}, {'$gte': value}, {'$lt': value}, {'$lte': value}

CompositeQuery(fields)

Composite query: {'field1': op1, 'field2': op2, ...}

EqOperator(value)

Equality operator: {'$eq': value}

IQueryOperator()

Base interface for all query operators.

IQueryVisitor()

Visitor for traversing query operator tree.

InOperator(values)

In operator: {'$in': [value1, value2, ...]}

IsNullOperator(value)

Null check operator: {'$is_null': True} or {'$is_null': False}

OrOperator(operands)

Logical OR: {'$or': [expr1, expr2, ...]}

RelOperator(query)

Relation operator: {'$rel': {'field': {'$eq': value}, ...}}

Exceptions

MergeConflict(existing_value, new_value)

Raised when merging two operators with incompatible values.

class ascetic_ddd.faker.domain.query.operators.IQueryOperator[source]

Bases: object

Base interface for all query operators.

abstractmethod accept(visitor)[source]
Return type:

TypeVar(T)

Parameters:
visitor : IQueryVisitor[__SPHINX_IMMATERIAL_TYPE_VAR__V_T]

class ascetic_ddd.faker.domain.query.operators.IQueryVisitor[source]

Bases: Generic[T]

Visitor for traversing query operator tree.

abstractmethod visit_eq(op)[source]
Return type:

TypeVar(T)

Parameters:
op : EqOperator

abstractmethod visit_comparison(op)[source]
Return type:

TypeVar(T)

Parameters:
op : ComparisonOperator

abstractmethod visit_in(op)[source]
Return type:

TypeVar(T)

Parameters:
op : InOperator

abstractmethod visit_is_null(op)[source]
Return type:

TypeVar(T)

Parameters:
op : IsNullOperator

abstractmethod visit_and(op)[source]
Return type:

TypeVar(T)

Parameters:
op : AndOperator

abstractmethod visit_or(op)[source]
Return type:

TypeVar(T)

Parameters:
op : OrOperator

abstractmethod visit_rel(op)[source]
Return type:

TypeVar(T)

Parameters:
op : RelOperator

abstractmethod visit_composite(op)[source]
Return type:

TypeVar(T)

Parameters:
op : CompositeQuery

exception ascetic_ddd.faker.domain.query.operators.MergeConflict(existing_value, new_value)[source]

Bases: Exception

Raised when merging two operators with incompatible values.

Parameters:
existing_value : Any

new_value : Any

class ascetic_ddd.faker.domain.query.operators.EqOperator(value)[source]

Bases: IQueryOperator

Equality operator: {‘$eq’: value}

Represents exact value match. Value can be: - Primitive (int, str, bool, None) - IQueryOperator (parsed subtree, before normalization)

Parameters:
value : Any

value
accept(visitor)[source]
Return type:

TypeVar(T)

Parameters:
visitor : IQueryVisitor[__SPHINX_IMMATERIAL_TYPE_VAR__V_T]

class ascetic_ddd.faker.domain.query.operators.ComparisonOperator(op, value)[source]

Bases: IQueryOperator

Comparison operator: {‘$ne’: value}, {‘$gt’: value}, {‘$gte’: value}, {‘$lt’: value}, {‘$lte’: value}

Supported ops: ‘$ne’, ‘$gt’, ‘$gte’, ‘$lt’, ‘$lte’

Parameters:
op : str

value : Any

SUPPORTED_OPS = frozenset({'$gt', '$gte', '$lt', '$lte', '$ne'})
op
value
accept(visitor)[source]
Return type:

TypeVar(T)

Parameters:
visitor : IQueryVisitor[__SPHINX_IMMATERIAL_TYPE_VAR__V_T]

class ascetic_ddd.faker.domain.query.operators.InOperator(values)[source]

Bases: IQueryOperator

In operator: {‘$in’: [value1, value2, …]}

Represents value membership check.

Parameters:
values : tuple[Any, ...]

values
accept(visitor)[source]
Return type:

TypeVar(T)

Parameters:
visitor : IQueryVisitor[__SPHINX_IMMATERIAL_TYPE_VAR__V_T]

class ascetic_ddd.faker.domain.query.operators.IsNullOperator(value)[source]

Bases: IQueryOperator

Null check operator: {‘$is_null’: True} or {‘$is_null’: False}

When value=True, matches None values. When value=False, matches non-None values.

Parameters:
value : bool

value
accept(visitor)[source]
Return type:

TypeVar(T)

Parameters:
visitor : IQueryVisitor[__SPHINX_IMMATERIAL_TYPE_VAR__V_T]

class ascetic_ddd.faker.domain.query.operators.AndOperator(operands)[source]

Bases: IQueryOperator

Implicit AND of operators at the same level.

Created by parser when multiple operators appear at the same level:

{‘$gt’: 5, ‘$lt’: 10} -> AndOperator((ComparisonOperator(‘$gt’, 5), ComparisonOperator(‘$lt’, 10)))

Not exposed as ‘$and’ in query syntax.

Parameters:
operands : tuple[IQueryOperator, ...]

operands
accept(visitor)[source]
Return type:

TypeVar(T)

Parameters:
visitor : IQueryVisitor[__SPHINX_IMMATERIAL_TYPE_VAR__V_T]

class ascetic_ddd.faker.domain.query.operators.OrOperator(operands)[source]

Bases: IQueryOperator

Logical OR: {‘$or’: [expr1, expr2, …]}

Each operand is an IQueryOperator.

Parameters:
operands : tuple[IQueryOperator, ...]

operands
accept(visitor)[source]
Return type:

TypeVar(T)

Parameters:
visitor : IQueryVisitor[__SPHINX_IMMATERIAL_TYPE_VAR__V_T]

class ascetic_ddd.faker.domain.query.operators.RelOperator(query)[source]

Bases: IQueryOperator

Relation operator: {‘$rel’: {‘field’: {‘$eq’: value}, …}}

Represents constraints on a related aggregate. Used by ReferenceProvider to specify criteria for the referenced aggregate. Wraps a CompositeQuery with the semantic meaning “these constraints are for a related aggregate, not for the current one”.

Parameters:
query : CompositeQuery

query
accept(visitor)[source]
Return type:

TypeVar(T)

Parameters:
visitor : IQueryVisitor[__SPHINX_IMMATERIAL_TYPE_VAR__V_T]

class ascetic_ddd.faker.domain.query.operators.CompositeQuery(fields)[source]

Bases: IQueryOperator

Composite query: {‘field1’: op1, ‘field2’: op2, …}

Represents a query with multiple field constraints. Used for composite primary keys or multi-field criteria.

Parameters:
fields : dict[str, IQueryOperator]

fields
accept(visitor)[source]
Return type:

TypeVar(T)

Parameters:
visitor : IQueryVisitor[__SPHINX_IMMATERIAL_TYPE_VAR__V_T]