neosqlite.collection.query_helper.query_builder module

Query Builder Mixin for NeoSQLite.

Provides Python-based query application methods (_apply_query). SQL WHERE clause building lives in _sql_query_builder.py (SqlQueryBuilderMixin).

neosqlite.collection.query_helper.query_builder._iter_leaf_values(document: dict[str, Any], parts: list[str]) Any | None[source]

Resolve a dotted path, expanding arrays along the way (#99).

Returns the list of leaf values found (arrays flattened one level per step), or None when the first segment is missing entirely.

class neosqlite.collection.query_helper.query_builder.QueryBuilderMixin[source]

Bases: SqlQueryBuilderMixin

A mixin class that provides query building capabilities.

This mixin assumes it will be used with a class that has: - self.collection (with db and name attributes) - self.jsonb.jsonb_supported - self.jsonb.json_function_prefix - self._build_expr_where_clause method (for handling $expr queries)

collection: Collection
jsonb: JSONBContext
_build_expr_where_clause: Any
_search_in_value(value: Any, search_term: str) bool[source]

Recursively search for a term in a value (string, dict, or list).

Parameters:
  • value – The value to search in

  • search_term – The term to search for

Returns:

True if the search term is found, False otherwise

Return type:

bool

_apply_query(query: dict[str, Any], document: dict[str, Any]) bool[source]

Applies a query to a document to determine if it matches the query criteria.

Handles logical operators ($and, $or, $nor, $not) and nested field paths. Processes both simple equality checks and complex query operators.

Parameters:
  • query (dict[str, Any]) – A dictionary representing the query criteria.

  • document (dict[str, Any]) – The document to apply the query to.

Returns:

True if the document matches the query, False otherwise.

Return type:

bool

_get_operator_fn(op: str) Any[source]

Retrieve the function associated with the given operator from the query_operators module.

Parameters:

op (str) – The operator string, which should start with a ‘$’ prefix.

Returns:

The function corresponding to the operator.

Return type:

Any

Raises: