Batch Operation Builders¶
BatchOperationBuilder - Builder for chaining operations across multiple keys.
- class aerospike_sdk.aio.operations.batch.BatchOpType[source]¶
Bases:
EnumType of batch operation.
- INSERT = 'insert'¶
- UPDATE = 'update'¶
- UPSERT = 'upsert'¶
- REPLACE = 'replace'¶
- REPLACE_IF_EXISTS = 'replace_if_exists'¶
- DELETE = 'delete'¶
- class aerospike_sdk.aio.operations.batch.BatchBinBuilder[source]¶
Bases:
objectBuilder for chaining bin operations within a batch key operation.
Example
batch.insert(key).bin(“name”).set_to(“Alice”).bin(“age”).set_to(25)
- set_to(value)[source]¶
Set a bin value.
- Parameters:
value (
Any) – The value to set.- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- append(value)[source]¶
Append a string to a bin value.
- Parameters:
value (
str) – The string to append.- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- prepend(value)[source]¶
Prepend a string to a bin value.
- Parameters:
value (
str) – The string to prepend.- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- select_from(expression, *, ignore_eval_failure=False)[source]¶
Read the result of an expression into this bin.
- Parameters:
- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- insert_from(expression, *, ignore_op_failure=False, ignore_eval_failure=False, delete_if_null=False)[source]¶
Write expression result to this bin only if it does not already exist.
- Parameters:
- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- update_from(expression, *, ignore_op_failure=False, ignore_eval_failure=False, delete_if_null=False)[source]¶
Write expression result to this bin only if it already exists.
- Parameters:
- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- class aerospike_sdk.aio.operations.batch.BatchKeyOperationBuilder[source]¶
Bases:
objectBuilder for a single key’s operation within a batch.
This class allows chaining bin operations and then continuing to add more keys to the batch.
Example
- batch.insert(key1).bin(“name”).set_to(“Alice”)
.update(key2).bin(“counter”).add(1)
- bin(bin_name)[source]¶
Start a bin operation chain.
- Parameters:
bin_name (
str) – The name of the bin.- Return type:
- Returns:
A BatchBinBuilder for chaining bin operations.
Example
batch.insert(key).bin(“name”).set_to(“Alice”).bin(“age”).set_to(25)
- put(bins)[source]¶
Set multiple bins at once.
- Parameters:
bins (
Dict[str,Any]) – Dictionary of bin name to value mappings.- Return type:
- Returns:
self for method chaining.
Example
batch.insert(key).put({“name”: “Alice”, “age”: 25})
- class aerospike_sdk.aio.operations.batch.BatchOperationBuilder[source]¶
Bases:
objectBuilder for chaining operations across multiple keys.
This class enables method chaining of operations on different keys, which are then executed as a single batch operation.
Example:
results = await session.batch() \ .insert(key1).bin("name").set_to("Alice").bin("age").set_to(25) \ .update(key2).bin("counter").add(1) \ .delete(key3) \ .execute()
The operations are collected and executed together using the async client’s batch_operate method for optimal performance.
- with_txn(txn)[source]¶
Opt this batch into (or out of) a specific transaction.
See
aerospike_sdk.aio.operations.query.QueryBuilder.with_txn()for semantics.- Parameters:
txn (
Optional[Txn]) – TheTxnto participate in, orNoneto opt out.- Return type:
- Returns:
This builder for chaining.
- insert(key)[source]¶
Add an insert (create only) operation for a key.
- Parameters:
key (
Key) – The key for the record.- Return type:
- Returns:
A BatchKeyOperationBuilder for chaining bin operations.
Example
batch.insert(key).bin(“name”).set_to(“Alice”)
- update(key)[source]¶
Add an update (update only) operation for a key.
- Parameters:
key (
Key) – The key for the record.- Return type:
- Returns:
A BatchKeyOperationBuilder for chaining bin operations.
Example
batch.update(key).bin(“counter”).add(1)
- upsert(key)[source]¶
Add an upsert (create or update) operation for a key.
- Parameters:
key (
Key) – The key for the record.- Return type:
- Returns:
A BatchKeyOperationBuilder for chaining bin operations.
Example
batch.upsert(key).bin(“name”).set_to(“Bob”)
- replace(key)[source]¶
Add a replace (create or replace) operation for a key.
- Parameters:
key (
Key) – The key for the record.- Return type:
- Returns:
A BatchKeyOperationBuilder for chaining bin operations.
Example
batch.replace(key).put({“name”: “Charlie”, “age”: 35})
- replace_if_exists(key)[source]¶
Add a replace-if-exists operation for a key.
This operation will fail if the record does not exist.
- Parameters:
key (
Key) – The key for the record.- Return type:
- Returns:
A BatchKeyOperationBuilder for chaining bin operations.
Example
batch.replace_if_exists(key).put({“name”: “Updated”, “status”: “active”})
- delete(key)[source]¶
Add a delete operation for a key.
- Parameters:
key (
Key) – The key for the record.- Return type:
- Returns:
A BatchKeyOperationBuilder for continuing the chain.
Example
batch.delete(key1).delete(key2).execute()
- async execute()[source]¶
Execute all batch operations.
Example:
stream = await ( session.batch() .insert(key1) .bin("name").set_to("Ada") .upsert(key2) .bin("n").set_to(1) .execute() ) rows = await stream.collect()
- Return type:
- Returns:
A
RecordStreamof per-keyRecordResultitems.- Raises:
ValueError – If no operations have been added.