neosqlite.collection.query_engine.crud_operations module¶
CRUD operations for the QueryEngine.
- class neosqlite.collection.query_engine.crud_operations.CRUDOperationsMixin(*args, **kwargs)[source]¶
Bases:
QueryEngineProtocolMixin class providing CRUD operations for QueryEngine.
- insert_one(document: dict[str, Any], session: ClientSession | None = None) InsertOneResult[source]¶
Insert a single document into the collection.
- Parameters:
document (dict[str, Any]) – The document to insert.
session (ClientSession, optional) – A ClientSession for transactions.
- Returns:
The result of the insert operation.
- Return type:
- insert_many(documents: list[dict[str, Any]], ordered: bool = True, session: ClientSession | None = None) InsertManyResult[source]¶
Insert multiple documents into the collection.
- Parameters:
documents (list[dict[str, Any]]) – List of documents to insert.
ordered (bool, optional) – If True, insert documents in the order they appear in the list. If an error occurs, the operation will stop. If False, the operation will continue even if an error occurs.
session (ClientSession, optional) – A ClientSession for transactions.
- Returns:
Result of the insert operation, containing a list of inserted document IDs.
- Return type:
- update_one(filter: dict[str, Any], update: dict[str, Any], upsert: bool = False, array_filters: list[dict[str, Any]] | None = None, session: ClientSession | None = None) UpdateResult[source]¶
Updates a single document in the collection based on the provided filter and update operations.
- Parameters:
filter (dict[str, Any]) – A dictionary specifying the query criteria for finding the document to update.
update (dict[str, Any]) – A dictionary specifying the update operations to apply to the document.
upsert (bool, optional) – If True, inserts a new document if no document matches the filter. Defaults to False.
array_filters (list[dict[str, Any]], optional) – A list of filter documents for array positional operators.
session (ClientSession, optional) – A ClientSession for transactions.
- Returns:
- An object containing information about the update operation,
including the count of matched and modified documents, and the upserted ID if applicable.
- Return type:
- _update_gridfs_file(filter: dict[str, Any], update: dict[str, Any], upsert: bool = False) UpdateResult[source]¶
Handle updates for GridFS files collections.
- _get_integer_id_for_oid(oid) int[source]¶
Get the integer ID for a given ObjectId.
This method delegates to the centralized get_integer_id_for_oid function to ensure consistent ID handling across all NeoSQLite components.
- Parameters:
oid – The ObjectId to look up.
- Returns:
The corresponding integer ID from the database.
- Return type:
int
- Raises:
ValueError – If the integer ID for the ObjectId cannot be found.
- _try_fast_update_one(filter: dict[str, Any], update: dict[str, Any]) UpdateResult | None[source]¶
Try to use a fast SQL UPDATE without fetching the document first.
This method attempts to execute a simple UPDATE in a single SQL statement without needing to first SELECT the document. This is much faster for simple field updates.
- Parameters:
filter – The query filter
update – The update operations
- Returns:
UpdateResult if fast path was successful, None otherwise
- update_many(filter: dict[str, Any], update: dict[str, Any], upsert: bool = False, array_filters: list[dict[str, Any]] | None = None, session: ClientSession | None = None) UpdateResult[source]¶
Update multiple documents based on a filter.
This method updates documents in the collection that match the given filter using the specified update.
- Parameters:
filter (dict[str, Any]) – A dictionary representing the filter to select documents to update.
update (dict[str, Any]) – A dictionary representing the updates to apply.
upsert (bool, optional) – If True, inserts a new document if no document matches the filter. Defaults to False.
array_filters (list[dict[str, Any]], optional) – A list of filter documents for array positional operators.
session (ClientSession, optional) – A ClientSession for transactions.
- Returns:
A result object containing information about the update operation.
- Return type:
- delete_one(filter: dict[str, Any], session: ClientSession | None = None) DeleteResult[source]¶
Delete a single document matching the filter.
- Parameters:
filter (dict[str, Any]) – A dictionary specifying the filter conditions for the document to delete.
session (ClientSession, optional) – A ClientSession for transactions.
- Returns:
- A result object indicating whether the deletion was
successful or not.
- Return type:
- delete_many(filter: dict[str, Any], session: ClientSession | None = None) DeleteResult[source]¶
Deletes multiple documents in the collection that match the provided filter.
- Parameters:
filter (dict[str, Any]) – A dictionary specifying the query criteria for finding the documents to delete.
session (ClientSession, optional) – A ClientSession for transactions.
- Returns:
A result object indicating whether the deletion was successful or not.
- Return type:
- replace_one(filter: dict[str, Any], replacement: dict[str, Any], upsert: bool = False, session: ClientSession | None = None) UpdateResult[source]¶
Replace one document in the collection that matches the filter with the replacement document.
- Parameters:
filter (dict[str, Any]) – A query that matches the document to replace.
replacement (dict[str, Any]) – The new document that replaces the matched document.
upsert (bool, optional) – If true, inserts the replacement document if no document matches the filter. Default is False.
session (ClientSession, optional) – A ClientSession for transactions.
- Returns:
- A result object containing the number of matched and
modified documents and the upserted ID.
- Return type:
- _abc_impl = <_abc._abc_data object>¶
- _is_protocol = False¶