GitHub

WithTransaction

API reference for WithTransaction.

Runs effects in a transaction (see SqlClientService.with_transaction).

Functions

__init__

__init__(options) -> None
ParameterTypeDescription
optionsTransactionOptions
def __init__(self, options: TransactionOptions) -> None:
    self._options = options
    semaphore_id = next(_semaphore_ids)
    self._semaphore_tag = cast(
        "type[Tag[Semaphore]]",
        types.new_class(
            f"TransactionSemaphore{semaphore_id}",
            (Tag[Semaphore],),
            {"key": f"effect/sql/SqlClient/TransactionSemaphore/{semaphore_id}"},
        ),
    )
    self._after_commit = make_after_commit(options.transaction_service)
    self._target = span_target(options.span_attributes)

__call__

__call__[A, E, R](effect) -> Effect[A, E | SqlError, R]
ParameterTypeDescription
effectEffect[A, E, R]

Returns Effect[A, E | SqlError, R]

def __call__[A, E, R](self, effect: Effect[A, E, R]) -> Effect[A, E | SqlError, R]:
    require_effect(effect, "effect")
    return uninterruptible_mask(
        lambda restore: use_span(
            "sql.transaction",
            lambda span: _WithFiber(lambda fiber: self._run(effect, restore, span, fiber)),
            kind="internal",
        )
    )