WriteSegmentBuilder

class aerospike_sdk.aio.operations.query.WriteSegmentBuilder[source]

Bases: _WriteVerbs

Accumulate scalar and CDT writes for the current operation’s key(s).

Obtained from QueryBuilder after a write verb or from WriteBinBuilder when chaining. Call put(), bin(), expression helpers, optional where() / TTL / generation guards, then execute() on this object or transition with query() / 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.

__init__(qb)[source]
with_txn(txn)[source]

Opt this write into (or out of) a specific transaction.

Delegates to the underlying QueryBuilder; see QueryBuilder.with_txn().

Parameters:

txn (Optional[Txn]) – The Txn to participate in, or None to run without a transaction.

Return type:

WriteSegmentBuilder

Returns:

This segment for chaining.

bin(bin_name)[source]

Start a bin-level write operation.

Parameters:

bin_name (str) – The bin to operate on.

Return type:

WriteBinBuilder

Returns:

A WriteBinBuilder for method chaining.

put(bins)[source]

Apply Operation.put for each bin in the mapping.

Parameters:

bins (dict) – Map of bin name to value.

Return type:

WriteSegmentBuilder

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.

set_bins(bins)[source]

Alias for put().

Return type:

WriteSegmentBuilder

add_operation(op)[source]

Append an operation (used by CDT action builders).

Return type:

None

set_to(bin_name, value)[source]

Set a bin to value.

Return type:

WriteSegmentBuilder

add(bin_name, value)[source]

Add a numeric value to a bin.

Return type:

WriteSegmentBuilder

increment_by(bin_name, value)[source]

Alias for add().

Return type:

WriteSegmentBuilder

get(bin_name)[source]

Read a bin value back within a write operate.

Return type:

WriteSegmentBuilder

append(bin_name, value)[source]

Append a string to a bin.

Return type:

WriteSegmentBuilder

prepend(bin_name, value)[source]

Prepend a string to a bin.

Return type:

WriteSegmentBuilder

remove_bin(bin_name)[source]

Delete a bin from the record.

Return type:

WriteSegmentBuilder

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:

WriteSegmentBuilder

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:

WriteSegmentBuilder

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:

WriteSegmentBuilder

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:

WriteSegmentBuilder

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:

WriteSegmentBuilder

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:

WriteSegmentBuilder

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:

QueryBuilder

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:

WriteSegmentBuilder

Returns:

self for method chaining.

Raises:

ValueError – If seconds is <= 0.

never_expire()[source]

Set this record to never expire (TTL = -1).

Return type:

WriteSegmentBuilder

Returns:

self for method chaining.

with_no_change_in_expiration()[source]

Preserve the record’s existing TTL (TTL = -2).

Return type:

WriteSegmentBuilder

Returns:

self for method chaining.

expiry_from_server_default()[source]

Use the namespace’s default TTL for this record (TTL = 0).

Return type:

WriteSegmentBuilder

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:

WriteSegmentBuilder

Returns:

self for method chaining.

Raises:

ValueError – If generation is <= 0.

durably_delete()[source]

Enable durable delete on the current segment.

Return type:

WriteSegmentBuilder

Returns:

self for method chaining.

respond_all_keys()[source]

Include results for missing keys in the stream.

Return type:

WriteSegmentBuilder

Returns:

self for method chaining.

fail_on_filtered_out()[source]

Mark filtered-out records with FILTERED_OUT result code.

Return type:

WriteSegmentBuilder

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_ERROR if it does not. All existing bins are removed and only the bins specified in this segment are written.

Return type:

WriteSegmentBuilder

Returns:

self for method chaining.

async execute(on_error=None)[source]

Run the parent QueryBuilder stack (same as self._qb.execute).

Parameters:

on_error (Union[ErrorStrategy, Callable[[Key, int, AerospikeError], None], None]) – Optional ErrorStrategy or error callback; see QueryBuilder.execute().

Return type:

RecordStream

Returns:

RecordStream of results.

Example::

stream = await session.upsert(key).put({“x”: 1}).execute() await stream.first_or_raise()

:raises Same as QueryBuilder.execute().: