neosqlite.collection.datetime_query_processor module¶
Datetime query processor for NeoSQLite with three-tier fallback mechanism.
This module provides a three-tier approach for handling datetime queries: 1. SQL tier: Direct SQL processing with json_* functions 2. Temp table tier: Temporary table approach for complex queries 3. Python tier: Pure Python processing as fallback
The SQL and temp table queries always use json_* functions not jsonb_* because we need to compare the datetime string, querying with jsonb_* will get byte instead of string. This extends the existing text search functionality to also use only json_* functions.
- class neosqlite.collection.datetime_query_processor.DateTimeQueryProcessor(collection, query_engine=None, use_global_kill_switch=False)[source]¶
Bases:
objectProcess datetime queries using a three-tier fallback mechanism.
The three-tier approach: 1. SQL tier: Direct SQL processing with json_* functions 2. Temp table tier: Temporary table approach for complex queries 3. Python tier: Pure Python processing as fallback
The SQL and temp table queries always use json_* functions not jsonb_* because we need to compare the datetime string, querying with jsonb_* will get byte instead of string.
- __init__(collection, query_engine=None, use_global_kill_switch=False)[source]¶
Initialize the DateTimeQueryProcessor with a collection.
- Parameters:
collection – The NeoSQLite collection to process datetime queries on
query_engine – Optional QueryEngine instance for accessing helpers
use_global_kill_switch – If True, use the global kill switch; if False, use local kill switch only
- set_kill_switch(enabled: bool)[source]¶
Set the kill switch to force fallback to Python implementation. Behavior depends on initialization setting: - If use_global_kill_switch=True: Sets the global kill switch (affects entire app) - If use_global_kill_switch=False: Sets local kill switch (affects only this instance)
- Parameters:
enabled – If True, forces fallback to Python implementation
- is_kill_switch_enabled() bool[source]¶
Check if the kill switch is enabled. Behavior depends on initialization setting: - If use_global_kill_switch=True: Checks global kill switch - If use_global_kill_switch=False: Checks local kill switch
- Returns:
True if kill switch is enabled, False otherwise
- process_datetime_query(query: dict[str, Any], use_kill_switch: bool | None = None) list[dict[str, Any]][source]¶
Process a datetime query using the three-tier fallback mechanism.
- Parameters:
query – MongoDB-style query dictionary containing datetime operations
use_kill_switch – Optional override for kill switch setting
- Returns:
List of matching documents
- _contains_datetime_operations(query: dict[str, Any]) bool[source]¶
Check if a query contains datetime operations.
- Parameters:
query – MongoDB-style query dictionary
- Returns:
True if query contains datetime operations, False otherwise
- _is_datetime_value(value: Any) bool[source]¶
Check if a value is a datetime object or datetime string.
- Parameters:
value – Value to check
- Returns:
True if value is datetime-related, False otherwise
- _is_datetime_regex(pattern: str) bool[source]¶
Check if a pattern is likely to be datetime-related.
- Parameters:
pattern – Pattern string (could be a regex pattern or a datetime string)
- Returns:
True if pattern is likely datetime-related, False otherwise
- _process_with_sql_tier(query: dict[str, Any]) list[dict[str, Any]] | None[source]¶
Process datetime query using SQL tier with json_* functions.
- Parameters:
query – MongoDB-style query dictionary
- Returns:
List of matching documents if successful, None otherwise
- class neosqlite.collection.datetime_query_processor.EnhancedDateTimeQueryProcessor(collection, query_engine=None)[source]¶
Bases:
DateTimeQueryProcessorEnhanced datetime query processor with additional datetime-specific query operators.
- __init__(collection, query_engine=None)[source]¶
Initialize the EnhancedDateTimeQueryProcessor with a collection.
- Parameters:
collection – The NeoSQLite collection to process datetime queries on
query_engine – Optional QueryEngine instance for accessing helpers
- _apply_datetime_query(query: dict[str, Any], document: dict[str, Any]) bool[source]¶
Apply datetime-specific query operations to a document.
- Parameters:
query – MongoDB-style query dictionary with datetime operations
document – Document to check against the query
- Returns:
True if document matches query, False otherwise
- process_complex_datetime_query(query: dict[str, Any], use_kill_switch: bool | None = None) list[dict[str, Any]][source]¶
Process complex datetime queries with additional datetime-specific logic.
- Parameters:
query – MongoDB-style query dictionary containing complex datetime operations
use_kill_switch – Optional override for kill switch setting
- Returns:
List of matching documents