| Copyright | (c) 2019-2022 Vaclav Svejcar |
|---|---|
| License | BSD-3-Clause |
| Maintainer | vaclav.svejcar@gmail.com |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | None |
| Language | Haskell2010 |
Headroom.IO.KVStore
Description
This is really simple key-value persistent store that uses SQLite as a backend. Main goal is to provide type-safe way how to define value keys, that can be later used to set/put the actual value into the store.
Synopsis
- type GetValueFn m = forall a. ValueCodec a => ValueKey a -> m (Maybe a)
- type PutValueFn m = forall a. ValueCodec a => ValueKey a -> a -> m ()
- data KVStore m = KVStore {
- kvGetValue :: GetValueFn m
- kvPutValue :: PutValueFn m
- class ValueCodec a where
- encodeValue :: a -> Text
- decodeValue :: Text -> Maybe a
- newtype ValueKey a = ValueKey Text
- newtype StorePath = StorePath Text
- inMemoryKVStore :: MonadIO m => m (KVStore m)
- sqliteKVStore :: MonadIO m => StorePath -> KVStore m
- valueKey :: Text -> ValueKey a
Type Aliases
type GetValueFn m Source #
Arguments
| = forall a. ValueCodec a | |
| => ValueKey a | key for the value |
| -> m (Maybe a) | value (if found) |
Gets the value for given ValueKey from the store.
type PutValueFn m Source #
Arguments
| = forall a. ValueCodec a | |
| => ValueKey a | key for the value |
| -> a | value to put into store |
| -> m () | operation result |
Puts the value for given ValueKey into the store.
Polymorphic record composed of key-value store operations, allowing to abstract over concrete implementation without (ab)using type classes.
Constructors
| KVStore | |
Fields
| |
Type Classes
class ValueCodec a where Source #
Represents way how to encode/decode concrete types into textual representation used by the store to hold values.
Methods
Arguments
| :: a | value to encode |
| -> Text | textual representation |
Encodes value into textual representation.
Decodes value from textual representation.
Instances
| ValueCodec Text Source # | |
Defined in Headroom.IO.KVStore | |
| ValueCodec UTCTime Source # | |
Defined in Headroom.IO.KVStore | |
Data Types
Type-safe representation of the key for specific value.
Path to the store (e.g. path of the SQLite database on filesystem).
Public Functions
inMemoryKVStore :: MonadIO m => m (KVStore m) Source #
Constructs non-persistent in-memory instance of KVStore.
Constructs persistent instance of KVStore that uses SQLite as a backend.