WriteSegmentBuilder¶
- class aerospike_sdk.aio.operations.query.WriteSegmentBuilder[source]¶
Bases:
_WriteVerbsAccumulate scalar and CDT writes for the current operation’s key(s).
Obtained from
QueryBuilderafter a write verb or fromWriteBinBuilderwhen chaining. Callput(),bin(), expression helpers, optionalwhere()/ TTL / generation guards, thenexecute()on this object or transition withquery()/ another write verb on the mixin.Example
Upsert two bins, then read the stream of results:
stream = await ( session.upsert(key) .put({"name": "Ada", "score": 100}) .execute() )
See also
QueryBuilder.execute(): Runs all chained operations.- with_txn(txn)[source]¶
Opt this write into (or out of) a specific transaction.
Delegates to the underlying
QueryBuilder; seeQueryBuilder.with_txn().- Parameters:
txn (
Optional[Txn]) – TheTxnto participate in, orNoneto run without a transaction.- Return type:
- Returns:
This segment for chaining.
See also
- bin(bin_name)[source]¶
Start a bin-level write operation.
- Parameters:
bin_name (
str) – The bin to operate on.- Return type:
- Returns:
A WriteBinBuilder for method chaining.
- put(bins)[source]¶
Apply
Operation.putfor each bin in the mapping.- Parameters:
bins (
dict) – Map of bin name to value.- Return type:
- Returns:
This segment for chaining.
- Example::
await session.upsert(key).put({“email”: “a@b.com”, “age”: 30}).execute()
See also
bin(): Per-bin CDT or scalar follow-ups.
- delete_record()[source]¶
Add a record-level delete to the current operate call.
Unlike
delete()which targets a different key, this deletes the record being operated on as part of the same atomic operation.Example:
stream = await ( session.upsert(key) .bin("name").get() .delete_record() .execute() )
- Return type:
- Returns:
This segment for chaining.
See also
delete(): Start a new delete segment for a key.
- touch_record()[source]¶
Add a record-level touch to the current operate call.
Resets the record’s TTL as part of an atomic multi-operation call. Combine with
expire_record_after_seconds()to set a new TTL.Example:
stream = await ( session.upsert(key) .bin("score").get() .touch_record() .expire_record_after_seconds(120) .execute() )
- Return type:
- Returns:
This segment for chaining.
See also
touch(): Start a new touch segment for a key.
- select_from(bin_name, expression, *, ignore_eval_failure=False)[source]¶
Read a computed value into a bin using an AEL expression.
- Return type:
- insert_from(bin_name, expression, *, ignore_op_failure=False, ignore_eval_failure=False, delete_if_null=False)[source]¶
Write expression result only if bin does not already exist.
- Return type:
- update_from(bin_name, expression, *, ignore_op_failure=False, ignore_eval_failure=False, delete_if_null=False)[source]¶
Write expression result only if bin already exists.
- Return type:
- upsert_from(bin_name, expression, *, ignore_op_failure=False, ignore_eval_failure=False, delete_if_null=False)[source]¶
Write expression result, creating or overwriting the bin.
- Return type:
- query(arg1, *more_keys)[source]¶
Finalize current write segment and start a read segment.
- Parameters:
arg1 (
Union[Key,List[Key]]) – A single Key or List[Key].*more_keys (
Key) – Additional keys (varargs).
- Return type:
- Returns:
The parent QueryBuilder for method chaining.
- where(expression)[source]¶
- Overloads:
self, expression (str) → WriteSegmentBuilder
self, expression (FilterExpression) → WriteSegmentBuilder
Set a filter expression on the current write segment.
- Parameters:
expression (
Union[str,FilterExpression]) – AEL string or pre-built FilterExpression.- Returns:
self for method chaining.
- expire_record_after_seconds(seconds)[source]¶
Set the TTL on the current write segment.
- Parameters:
seconds (
int) – Time-to-live in seconds (must be > 0).- Return type:
- Returns:
self for method chaining.
- Raises:
ValueError – If seconds is <= 0.
- never_expire()[source]¶
Set this record to never expire (TTL = -1).
- Return type:
- Returns:
self for method chaining.
- with_no_change_in_expiration()[source]¶
Preserve the record’s existing TTL (TTL = -2).
- Return type:
- Returns:
self for method chaining.
- expiry_from_server_default()[source]¶
Use the namespace’s default TTL for this record (TTL = 0).
- Return type:
- Returns:
self for method chaining.
- ensure_generation_is(generation)[source]¶
Set expected generation for optimistic locking on the current segment.
- Parameters:
generation (
int) – The expected generation number (must be > 0).- Return type:
- Returns:
self for method chaining.
- Raises:
ValueError – If generation is <= 0.
- durably_delete()[source]¶
Enable durable delete on the current segment.
- Return type:
- Returns:
self for method chaining.
- respond_all_keys()[source]¶
Include results for missing keys in the stream.
- Return type:
- Returns:
self for method chaining.
- fail_on_filtered_out()[source]¶
Mark filtered-out records with
FILTERED_OUTresult code.- Return type:
- Returns:
self for method chaining.
- replace_only()[source]¶
Change the current segment to replace-if-exists semantics.
The record must already exist; the operation fails with
KEY_NOT_FOUND_ERRORif it does not. All existing bins are removed and only the bins specified in this segment are written.- Return type:
- Returns:
self for method chaining.
- async execute(on_error=None)[source]¶
Run the parent
QueryBuilderstack (same asself._qb.execute).- Parameters:
on_error (
Union[ErrorStrategy,Callable[[Key,int,AerospikeError],None],None]) – OptionalErrorStrategyor error callback; seeQueryBuilder.execute().- Return type:
- Returns:
RecordStreamof results.
- Example::
stream = await session.upsert(key).put({“x”: 1}).execute() await stream.first_or_raise()
:raises Same as
QueryBuilder.execute().: