Module Lmdb.Txn

Series of operations on an environment performed atomically.

type -'perm t constraint 'perm = [< `Read | `Write ]

A transaction handle. A transaction may be read-only or read-write.

val go : 'perm perm -> ?⁠txn:'perm t -> Env.t -> ('perm t -> 'a) -> 'a option

go perm env f runs a transaction with perm read/write permissions in env.

The function f txn will receive the transaction handle. All changes to the environment env done using the transaction handle will be persisted to the environment only when f returns. After f returned, the transaction handle is invalid and should therefore not be leaked outside f.

returns

None if the transaction was aborted with abort, and Some _ otherwise.

parameter txn

Create a child transaction to txn. This is not supported on an env with Env.Flags.write_map.

Here is an example incrementing a value atomically:

go rw env begin fun txn ->
  let v = Map.get ~txn k in
  Map.add ~txn k (v+1) ;
  v
end
val abort : _ t -> _

abort txn aborts transaction txn and the current go function, which will return None.

val env : 'perm t -> Env.t

env txn returns the environment of txn