neosqlite.collection.query_helper package¶
Submodules¶
- neosqlite.collection.query_helper.aggregation module
AggregationMixinAggregationMixin.self.collectionAggregationMixin.self._jsonb_supportedAggregationMixin.self._json_function_prefixAggregationMixin.self._json_each_functionAggregationMixin.self._build_simple_where_clauseAggregationMixin.self._reorder_pipeline_for_indexesAggregationMixin.self._estimate_pipeline_costAggregationMixin.self._optimize_match_pushdownAggregationMixin.self._is_datetime_indexed_fieldAggregationMixin.self._build_group_queryAggregationMixin.self._apply_queryAggregationMixin.collectionAggregationMixin._jsonb_supportedAggregationMixin._json_function_prefixAggregationMixin._json_each_functionAggregationMixin._build_simple_where_clauseAggregationMixin._reorder_pipeline_for_indexesAggregationMixin._estimate_pipeline_costAggregationMixin._optimize_match_pushdownAggregationMixin._is_datetime_indexed_fieldAggregationMixin._apply_queryAggregationMixin._build_aggregation_query()AggregationMixin._optimize_unwind_group_pattern()AggregationMixin._build_unwind_query()AggregationMixin._build_unwind_from_clause()AggregationMixin._build_unwind_from_clause_impl()AggregationMixin._find_parent_unwind()AggregationMixin._build_sort_skip_limit_clauses()AggregationMixin._build_group_query()AggregationMixin._process_group_stage()AggregationMixin._run_subpipeline()AggregationMixin._apply_projection()
- neosqlite.collection.query_helper.crud_operations module
- neosqlite.collection.query_helper.fill_stage module
- neosqlite.collection.query_helper.graph_lookup module
- neosqlite.collection.query_helper.helpers module
- neosqlite.collection.query_helper.positional_update module
- neosqlite.collection.query_helper.query_builder module
QueryBuilderMixinQueryBuilderMixin.collectionQueryBuilderMixin._jsonb_supportedQueryBuilderMixin._json_function_prefixQueryBuilderMixin._build_expr_where_clauseQueryBuilderMixin._is_text_search_query()QueryBuilderMixin._build_text_search_query()QueryBuilderMixin._build_other_fields_clause()QueryBuilderMixin._categorize_ids()QueryBuilderMixin._build_id_operator_clause()QueryBuilderMixin._categorize_id_value()QueryBuilderMixin._build_field_clause()QueryBuilderMixin._build_simple_where_clause()QueryBuilderMixin._build_sort_clause()QueryBuilderMixin._build_pagination_clause()QueryBuilderMixin._build_operator_clause()QueryBuilderMixin._search_in_value()QueryBuilderMixin._apply_query()QueryBuilderMixin._get_operator_fn()
- neosqlite.collection.query_helper.query_optimizer module
QueryOptimizerMixinQueryOptimizerMixin.collectionQueryOptimizerMixin._jsonb_supportedQueryOptimizerMixin._json_function_prefixQueryOptimizerMixin._get_indexed_fields()QueryOptimizerMixin._estimate_result_size()QueryOptimizerMixin._estimate_query_cost()QueryOptimizerMixin._estimate_pipeline_cost()QueryOptimizerMixin._optimize_match_pushdown()QueryOptimizerMixin._is_datetime_indexed_field()QueryOptimizerMixin._reorder_pipeline_for_indexes()
- neosqlite.collection.query_helper.schema_compiler module
- neosqlite.collection.query_helper.schema_validator module
- neosqlite.collection.query_helper.translation_cache module
CacheEntryTranslationCacheTranslationCache.DEFAULT_MAX_SIZETranslationCache.__init__()TranslationCache.get()TranslationCache.put()TranslationCache.make_key()TranslationCache._extract_structure()TranslationCache.get_stats()TranslationCache.clear()TranslationCache.resize()TranslationCache.evict()TranslationCache.contains()TranslationCache.get_entry()TranslationCache._get_entry_hit_count()TranslationCache.dump()TranslationCache.is_enabled()
- neosqlite.collection.query_helper.update_operations module
UpdateOperationsMixinUpdateOperationsMixin.collectionUpdateOperationsMixin._jsonb_supportedUpdateOperationsMixin._json_function_prefixUpdateOperationsMixin._get_integer_id_for_oidUpdateOperationsMixin._internal_update()UpdateOperationsMixin._can_use_sql_updates()UpdateOperationsMixin._perform_sql_update()UpdateOperationsMixin._perform_enhanced_sql_update()UpdateOperationsMixin._get_document_fields()UpdateOperationsMixin._build_update_clause()UpdateOperationsMixin._build_sql_update_clause()UpdateOperationsMixin._perform_python_update()UpdateOperationsMixin._validate_inc_mul_types_sql()
- neosqlite.collection.query_helper.utils module
- neosqlite.collection.query_helper.window_operators module
Module contents¶
- class neosqlite.collection.query_helper.QueryHelper(collection)[source]¶
Bases:
CRUDOperationsMixin,UpdateOperationsMixin,QueryBuilderMixin,AggregationMixin,QueryOptimizerMixinA helper class for the QueryEngine that provides methods for building queries, performing updates, and processing aggregation pipelines.
This class contains the core logic for translating MongoDB-like queries and operations into SQL statements that can be executed against the SQLite database. It handles both simple operations that can be done directly with SQL JSON functions and complex operations that require Python-based processing.
The class is composed of several mixins: - CRUDOperationsMixin: Insert, replace, delete operations - UpdateOperationsMixin: Update operations (SQL and Python-based) - QueryBuilderMixin: WHERE clause building and query application - AggregationMixin: Aggregation pipeline processing - QueryOptimizerMixin: Query optimization and cost estimation
- __init__(collection)[source]¶
Initialize the QueryHelper with a collection.
- Parameters:
collection – The collection instance this QueryHelper will operate on.
- _normalize_id_query(query: dict[str, Any]) dict[str, Any][source]¶
Normalize ID types in a query dictionary to correct common mismatches.
This method delegates to the centralized normalize_id_query_for_db function to ensure consistent ID handling across all NeoSQLite components.
- Parameters:
query – The query dictionary to process
- Returns:
A new query dictionary with corrected ID types
- _get_integer_id_for_oid(oid: Any) int[source]¶
Get the integer ID for a given ObjectId or other ID type.
- Parameters:
oid – The ID value (can be ObjectId, int, str, etc.)
- Returns:
The integer ID from the database
- Return type:
int
- _validate_json_document(json_str: str) bool[source]¶
Validate JSON document using SQLite’s json_valid function.
- Parameters:
json_str – The JSON string to validate
- Returns:
True if valid, False otherwise
- Return type:
bool
- _get_json_error_position(json_str: str) int[source]¶
Get position of JSON error using json_error_position().
- Parameters:
json_str – The JSON string to check
- Returns:
Position of error, or -1 if valid/not supported
- Return type:
int
- _build_expr_where_clause(query: dict[str, Any]) tuple[str, list[Any], list[str]] | None[source]¶
Build a SQL WHERE clause for $expr queries using the 3-tier approach. Also handles other query fields combined with $expr.
Tier Selection Logic: - Tier 1 (Simple): Direct SQL WHERE with json_extract/jsonb_extract - Tier 2 (Complex): Temporary tables with pre-computed field extractions - Tier 3 (Fallback): Python evaluation for unsupported operations
- Parameters:
query – Query dictionary containing $expr and potentially other fields
- Returns:
Tuple of (SQL WHERE clause, parameters, tables) or None for Python fallback
- _build_other_fields_clause(query: dict[str, Any], expr: dict[str, Any]) tuple[str, list[Any]] | None[source]¶
Helper to build WHERE clause for non-$expr fields.
- _analyze_expr_complexity(expr: dict[str, Any]) int[source]¶
Analyze expression complexity to determine appropriate tier.
Complexity scoring: - Base expression: 1 point - Each nested operator: +1 point - Arithmetic operators: +1 point each - Conditional operators: +2 points each - Array operators: +2 points each - Type conversion: +1 point each
Tier thresholds: - 1-2: Tier 1 (simple SQL WHERE) - 3-8: Tier 2 (temporary tables) - 9+: Tier 3 (Python fallback)
- Parameters:
expr – The $expr expression
- Returns:
Complexity score
- Return type:
int
- _combine_expr_with_other_fields(sql_expr: str, params: list[Any], query: dict[str, Any], expr: dict[str, Any]) tuple[str, list[Any], list[str]] | None[source]¶
Combine $expr SQL with other query fields.
- Parameters:
sql_expr – The $expr SQL expression
params – SQL parameters
query – Full query dictionary
expr – The $expr expression
- Returns:
Tuple of (WHERE clause, parameters, tables) or None for Python fallback