acid-state-0.16.1.3: Add ACID guarantees to any serializable Haskell data structure.

Copyright | PublicDomain
Maintainer | lemmih@gmail.com
Portability | non-portable (uses GHC extensions)
Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Acid

Description

AcidState container using a transaction log on disk.

To see how it all fits together, have a look at these example https://github.com/acid-state/acid-state/tree/master/examples.

Synopsis

- data AcidState st
- openLocalState :: (Typeable st, IsAcidic st, SafeCopy st) => st -> IO (AcidState st)
- openLocalStateFrom :: (IsAcidic st, SafeCopy st) => FilePath -> st -> IO (AcidState st)
- closeAcidState :: AcidState st -> IO ()
- createCheckpoint :: AcidState st -> IO ()
- createArchive :: AcidState st -> IO ()
- update :: UpdateEvent event => AcidState (EventState event) -> event -> IO (EventResult event)
- query :: QueryEvent event => AcidState (EventState event) -> event -> IO (EventResult event)
- type EventResult ev = MethodResult ev
- type EventState ev = MethodState ev
- class Method ev => UpdateEvent ev
- class Method ev => QueryEvent ev
- data Update st a
- data Query st a
- class IsAcidic st
- makeAcidic :: Name -> [Name] -> Q [Dec]
- liftQuery :: Query st a -> Update st a

# Documentation

data AcidState st Source #

State container offering full ACID (Atomicity, Consistency, Isolation and Durability) guarantees.

`Atomicity`
  State changes are all-or-nothing. This is what you'd expect of any state variable in Haskell and AcidState doesn't change that.
`Consistency`
  No event or set of events will break your data invariants.
`Isolation`
  Transactions cannot interfere with each other even when issued in parallel.
`Durability`
  Successful transaction are guaranteed to survive unexpected system shutdowns (both those caused by hardware and software).

openLocalState Source #

Arguments

:: (Typeable st, IsAcidic st, SafeCopy st) |
=> st | Initial state value. This value is only used if no checkpoint is found.
-> IO (AcidState st) |

Create an AcidState given an initial value.

This will create or resume a log found in the "state/[typeOf state]/" directory.

openLocalStateFrom Source #

Arguments

:: (IsAcidic st, SafeCopy st) |
=> FilePath | Location of the checkpoint and transaction files.
-> st | Initial state value. This value is only used if no checkpoint is found.
-> IO (AcidState st) |

Create an AcidState given a log directory and an initial value.

This will create or resume a log found in `directory`. Running two AcidState's from the same directory is an error but will not result in dataloss.

closeAcidState :: AcidState st -> IO () Source #

createCheckpoint :: AcidState st -> IO () Source #

createArchive :: AcidState st -> IO () Source #

update :: UpdateEvent event => AcidState (EventState event) -> event -> IO (EventResult event) Source #

Issue an Update event and wait for its result. Once this call returns, you are guaranteed that the changes to the state are durable. Events may be issued in parallel.

It's a run-time error to issue events that aren't supported by the AcidState.

query :: QueryEvent event => AcidState (EventState event) -> event -> IO (EventResult event) Source #

Issue a Query event and wait for its result. Events may be issued in parallel.

type EventResult ev = MethodResult ev Source #

Events return the same thing as Methods. The exact type of `EventResult` depends on the event.

type EventState ev = MethodState ev Source #

class Method ev => UpdateEvent ev Source #

All UpdateEvents are also Methods.

class Method ev => QueryEvent ev Source #

All QueryEvents are also Methods.

data Update st a Source #

Context monad for Update events.

#### Instances

Instances details

MonadState st (Update st) Source # |
Instance details Defined in Data.Acid.Common Methods get :: Update st st Source # put :: st -> Update st () Source # state :: (st -> (a, st)) -> Update st a Source #
Applicative (Update st) Source # |
Instance details Defined in Data.Acid.Common Methods pure :: a -> Update st a Source # (<*>) :: Update st (a -> b) -> Update st a -> Update st b Source # liftA2 :: (a -> b -> c) -> Update st a -> Update st b -> Update st c Source # (*>) :: Update st a -> Update st b -> Update st b Source # (<*) :: Update st a -> Update st b -> Update st a Source #
Functor (Update st) Source # |
Instance details Defined in Data.Acid.Common Methods fmap :: (a -> b) -> Update st a -> Update st b Source # (<$) :: a -> Update st b -> Update st a Source #
Monad (Update st) Source # |
Instance details Defined in Data.Acid.Common Methods (>>=) :: Update st a -> (a -> Update st b) -> Update st b Source # (>>) :: Update st a -> Update st b -> Update st b Source # return :: a -> Update st a Source #

data Query st a Source #

Context monad for Query events.

#### Instances

Instances details

MonadReader st (Query st) Source # |
Instance details Defined in Data.Acid.Common Methods ask :: Query st st Source # local :: (st -> st) -> Query st a -> Query st a Source # reader :: (st -> a) -> Query st a Source #
Applicative (Query st) Source # |
Instance details Defined in Data.Acid.Common Methods pure :: a -> Query st a Source # (<*>) :: Query st (a -> b) -> Query st a -> Query st b Source # liftA2 :: (a -> b -> c) -> Query st a -> Query st b -> Query st c Source # (*>) :: Query st a -> Query st b -> Query st b Source # (<*) :: Query st a -> Query st b -> Query st a Source #
Functor (Query st) Source # |
Instance details Defined in Data.Acid.Common Methods fmap :: (a -> b) -> Query st a -> Query st b Source # (<$) :: a -> Query st b -> Query st a Source #
Monad (Query st) Source # |
Instance details Defined in Data.Acid.Common Methods (>>=) :: Query st a -> (a -> Query st b) -> Query st b Source # (>>) :: Query st a -> Query st b -> Query st b Source # return :: a -> Query st a Source #

class IsAcidic st Source #

Minimal complete definition

acidEvents

makeAcidic :: Name -> [Name] -> Q [Dec] Source #

Create the control structures required for acid states using Template Haskell.

This code:

    myUpdate :: Argument -> Update State Result
    myUpdate arg = ...

    myQuery :: Argument -> Query State Result
    myQuery arg = ...

    $(makeAcidic ''State ['myUpdate, 'myQuery])

will make `State` an instance of `IsAcidic` and provide the following events:

    data MyUpdate = MyUpdate Argument
    data MyQuery  = MyQuery Argument

liftQuery :: Query st a -> Update st a Source #

Run a query in the Update Monad.