neosqlite.bulk_operations module

class neosqlite.bulk_operations.BulkOperation[source]

Bases: ABC

Base class for bulk operations.

__init__() None
_abc_impl = <_abc._abc_data object>
class neosqlite.bulk_operations.InsertOperation(document: dict[str, Any])[source]

Bases: BulkOperation

Represents an insert operation in a bulk operation.

document: dict[str, Any]
__init__(document: dict[str, Any]) None
_abc_impl = <_abc._abc_data object>
class neosqlite.bulk_operations.UpdateOperation(filter: dict[str, Any], update: dict[str, Any], upsert: bool = False, multi: bool = False)[source]

Bases: BulkOperation

Represents an update operation in a bulk operation.

filter: dict[str, Any]
update: dict[str, Any]
upsert: bool
multi: bool
__init__(filter: dict[str, Any], update: dict[str, Any], upsert: bool = False, multi: bool = False) None
_abc_impl = <_abc._abc_data object>
class neosqlite.bulk_operations.DeleteOperation(filter: dict[str, Any], multi: bool = False)[source]

Bases: BulkOperation

Represents a delete operation in a bulk operation.

filter: dict[str, Any]
multi: bool
__init__(filter: dict[str, Any], multi: bool = False) None
_abc_impl = <_abc._abc_data object>
class neosqlite.bulk_operations.BulkOperationContext(bulk_operations: list[BulkOperation], filter: dict[str, Any])[source]

Bases: object

Context for bulk operations that supports find/update/delete operations.

__init__(bulk_operations: list[BulkOperation], filter: dict[str, Any])[source]

Initializes the BulkOperationContext.

Parameters:
  • bulk_operations – A list to which bulk operations will be added.

  • filter – The filter to be used for the operations.

upsert()[source]

Set the upsert flag for the next operation.

This method sets the upsert flag, which determines whether the next operation should insert a new document if no matching document is found.

Returns:

The current context object for chaining further operations.

Return type:

BulkOperationContext

update_one(update: dict[str, Any])[source]

Add an update one operation to the bulk operations list.

This method appends an update one operation to the bulk operations list. The operation will update a single document that matches the filter with the specified update and handle the upsert flag.

Parameters:

update (dict[str, Any]) – The update dictionary containing the fields to be updated.

Returns:

The current context object for chaining further operations.

Return type:

BulkOperationContext

update_many(update: dict[str, Any])[source]

Add an update many operation to the bulk operations list.

This method appends an update many operation to the bulk operations list. The operation will update all documents that match the filter with the specified update and handle the upsert flag.

Parameters:

update (dict[str, Any]) – The update dictionary containing the fields to be updated.

Returns:

The current context object for chaining further operations.

Return type:

BulkOperationContext

delete_one()[source]

Add a delete one operation to the bulk operations list.

This method appends a delete one operation to the bulk operations list. The operation will delete a single document that matches the filter.

Returns:

The current context object for chaining further operations.

Return type:

BulkOperationContext

delete_many()[source]

Add a delete many operation to the bulk operations list.

This method appends a delete many operation to the bulk operations list. The operation will delete all documents that match the filter.

Returns:

The current context object for chaining further operations.

Return type:

BulkOperationContext

replace_one(replacement: dict[str, Any])[source]

Add a replace one operation to the bulk operations list.

This method appends a replace one operation to the bulk operations list. The operation will replace a single document that matches the filter with the specified replacement.

The replacement dictionary should contain the fields to be updated. The method will exclude the _id field from the replacement to prevent replacing the document’s identifier.

Returns:

The current context object for chaining further operations.

Return type:

BulkOperationContext

class neosqlite.bulk_operations.BulkOperationExecutor(collection: neosqlite.Collection, ordered: bool = True)[source]

Bases: object

Executor for bulk operations.

__init__(collection: neosqlite.Collection, ordered: bool = True)[source]

Initialize the BulkOperationExecutor.

This method initializes a new BulkOperationExecutor with the given collection and ordering flag. The executor will execute operations in the order they are added if the ordered flag is True. Otherwise, the executor may execute operations in any order.

Parameters:
  • collection (neosqlite.Collection) – The collection to perform operations on.

  • ordered (bool, optional) – Whether to execute operations in order. Defaults to True.

add(operation)[source]

Add an operation to the bulk operations list.

For PyMongo API compatibility, accepts InsertOne, UpdateOne, DeleteOne operations.

Parameters:

operation – The operation to add (InsertOne, UpdateOne, DeleteOne, etc.)

Returns:

The current executor for chaining

Return type:

BulkOperationExecutor

insert(document: dict[str, Any])[source]

Add an insert operation to the bulk operations list.

This method appends an insert operation to the bulk operations list. The operation will insert the specified document into the collection.

Parameters:

document (dict[str, Any]) – The document to be inserted.

Returns:

The current context object for chaining further operations.

Return type:

BulkOperationContext

find(filter: dict[str, Any])[source]

Create a context for find-based operations.

This method creates a new BulkOperationContext for find-based operations with the given filter.

Parameters:

filter (dict[str, Any]) – The filter to be used for find operations.

Returns:

A new BulkOperationContext object for chaining find operations.

Return type:

BulkOperationContext

execute(session: ClientSession | None = None) BulkWriteResult[source]

Execute all bulk operations.

This method executes all bulk operations in the current context. If ordered is True, operations are executed in the order they were added. Otherwise, operations may be executed in any order.

Parameters:

session (ClientSession, optional) – A ClientSession for transactions.

Returns:

A result object containing the counts of inserted, matched, modified, deleted, and upserted documents.

Return type:

BulkWriteResult

_execute_ordered(session: ClientSession | None = None) BulkWriteResult[source]

Execute operations in order.

Parameters:

session (ClientSession, optional) – A ClientSession for transactions.

Returns:

A result object containing the counts of inserted, matched, modified, deleted, and upserted documents.

Return type:

BulkWriteResult

_execute_unordered(session: ClientSession | None = None) BulkWriteResult[source]

Execute operations in any order, continuing on individual failures.

Unlike ordered execution, a failure in one operation does not prevent subsequent operations from being attempted.

Parameters:

session (ClientSession, optional) – A ClientSession for transactions.

Returns:

A result object containing the counts of inserted, matched, modified, deleted, and upserted documents.

Return type:

BulkWriteResult