Documentation

TypeDB.Tx

Transactions #

Tx m α is a transaction body of mode m that returns α. Bodies compose with do notation, raise and catch TypeDBError, and run IO (whose errors become TypeDBError.io).

Tx is an irreducible definition, not an abbreviation, so that Tx .read α and Tx .write α are different types: a body that writes cannot be passed where a read body is expected. Operations take an [Allows m need] instance, so a read-mode body cannot call one that needs a write.

Driver.runSync is the transactor: it opens the transaction, runs the body, commits a write or schema transaction when the body succeeds, and closes the transaction without committing when the body fails. A retry policy can re-run the whole body when the commit loses a conflict.

structure TypeDB.TxCtx :

What a transaction body runs against.

Instances For
    @[irreducible]
    def TypeDB.Tx (_m : TxMode) (α : Type) :

    A transaction body of mode m returning α: a reader over the transaction's context. It is irreducible, so Tx .read α and Tx .write α stay different types, while the compiler still sees a ReaderT over EIO and turns loops over it into plain loops.

    Equations
    Instances For
      @[inline]
      def TypeDB.Tx.mk {m : TxMode} {α : Type} (f : TxCtx → EIO TypeDBError α) :
      Tx m α
      Equations
      Instances For
        @[inline]
        def TypeDB.Tx.run {m : TxMode} {α : Type} (x : Tx m α) :
        Equations
        Instances For
          @[instance_reducible]
          instance TypeDB.Tx.instMonad {m : TxMode} :
          Monad (Tx m)
          Equations
          • One or more equations did not get rendered due to their size.
          @[instance_reducible]
          Equations
          @[instance_reducible]
          Equations
          @[instance_reducible]
          Equations
          @[inline]
          def TypeDB.Tx.widen {m n : TxMode} {α : Type} [m.Allows n] (x : Tx n α) :
          Tx m α

          Runs a body of a weaker mode inside a stronger transaction.

          Equations
          Instances For
            @[instance_reducible]
            instance TypeDB.Tx.instInhabited {m : TxMode} {α : Type} :
            Inhabited (Tx m α)
            Equations
            @[inline]

            The transaction's context.

            Equations
            Instances For
              @[inline]
              def TypeDB.Tx.native {m : TxMode} {α : Type} (x : Native.NIO α) :
              Tx m α

              Runs a native call, classifying its error.

              Equations
              Instances For
                @[inline]
                def TypeDB.Tx.fail {m : TxMode} {α : Type} (e : TypeDBError) :
                Tx m α

                Raises a typed error.

                Equations
                Instances For

                  Rolls back the writes made so far without ending the transaction.

                  Equations
                  Instances For
                    @[reducible, inline]
                    abbrev TypeDB.MonadTypeDB (m : TxMode) (n : Type → Type) :

                    Transactions that may implement Tx m operations, for user monad stacks such as ReaderT Env (Tx .write). Any monad with a MonadLiftT (Tx m) instance qualifies.

                    Equations
                    Instances For
                      inductive TypeDB.Backoff :

                      Backoff between retries.

                      Instances For
                        Equations
                        Instances For

                          When run re-runs a transaction body.

                          Instances For
                            Equations
                            Instances For
                              def TypeDB.Driver.runOnce {α : Type} (d : Driver) (db : String) (mode : TxMode) (body : Tx mode α) (opts : TxOptions := { }) :

                              Opens one transaction, runs body, and commits (write and schema mode) or closes (read mode). If the body fails, the transaction is closed without committing and the error is returned.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                def TypeDB.Driver.runSync {α : Type} (d : Driver) (db : String) (mode : TxMode) (body : Tx mode α) (retry : RetryPolicy := RetryPolicy.never) (opts : TxOptions := { }) :

                                Runs a transaction on the calling thread, retrying the whole body on commit conflicts if retry says so.

                                Equations
                                Instances For
                                  def TypeDB.Driver.runSync.go {α : Type} (d : Driver) (db : String) (mode : TxMode) (body : Tx mode α) (opts : TxOptions) (backoff : Backoff) (attempt : Nat) :

                                  fuel is the number of retries left.

                                  Equations
                                  Instances For