| Copyright | © 2022-2023 IOHK 2023-2025 Cardano Foundation |
|---|---|
| License | Apache-2.0 |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Data.DBVar
Description
DBVar represents a mutable variable that stores one Haskell value
in volatile memory (RAM),
but mirrors the value to persistent storage,
for example to a database on disk.
Storerepresents the storage facility to which the variable is mirrored.- Read-access is from volatile memory and highly concurrent.
- Updates are incremental and use delta types, see Data.Delta.
Synopsis
- data DBVar m delta
- readDBVar :: (Delta da, a ~ Base da) => DBVar m da -> m a
- updateDBVar :: (Delta da, Monad m) => DBVar m da -> da -> m ()
- modifyDBVar :: (Delta da, Monad m, a ~ Base da) => DBVar m da -> (a -> (da, b)) -> m b
- modifyDBMaybe :: (Delta da, Monad m, a ~ Base da) => DBVar m da -> forall b. (a -> (Maybe da, b)) -> m b
- initDBVar :: (MonadSTM m, MonadThrow m, MonadEvaluate m, MonadMask m, Delta da, a ~ Base da) => UpdateStore m da -> a -> m (DBVar m da)
- loadDBVar :: (MonadSTM m, MonadThrow m, MonadEvaluate m, MonadMask m, Delta da) => UpdateStore m da -> m (DBVar m da)
Documentation
A DBVar m delta is a mutable reference to a Haskell value of type a.
The type delta is a delta type for this value type a,
that is we have a ~ Base delta.
The Haskell value is cached in memory, in weak head normal form (WHNF).
However, whenever the value is updated, a copy of the value will be written
to persistent storage like a file or database on disk;
the specific storage facility is represented by a Store.
For efficient updates, the delta type delta is used in the update.
Concurrency: DBVar fully supports concurrent reads and updates.
- Updates are atomic and will block other updates.
- Reads will not be blocked during an update (except for a small moment where the new value atomically replaces the old one).
readDBVar :: (Delta da, a ~ Base da) => DBVar m da -> m a Source #
Read the current value of the DBVar.
updateDBVar :: (Delta da, Monad m) => DBVar m da -> da -> m () Source #
Update the value of the DBVar using a delta type.
The new value will be evaluated to weak head normal form.
modifyDBVar :: (Delta da, Monad m, a ~ Base da) => DBVar m da -> (a -> (da, b)) -> m b Source #
Modify the value in a DBVar.
The new value will be evaluated to weak head normal form (WHNF).
modifyDBMaybe :: (Delta da, Monad m, a ~ Base da) => DBVar m da -> forall b. (a -> (Maybe da, b)) -> m b Source #
Maybe modify the value in a DBVar
If updated, the new value will be evaluated to weak head normal form (WHNF).
Arguments
| :: (MonadSTM m, MonadThrow m, MonadEvaluate m, MonadMask m, Delta da) | |
| => UpdateStore m da |
|
| -> m (DBVar m da) |