headroom-0.4.3.0: License Header Manager
Copyright(c) 2019-2022 Vaclav Svejcar
LicenseBSD-3-Clause
Maintainervaclav.svejcar@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

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 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.

data KVStore m Source #

Polymorphic record composed of key-value store operations, allowing to abstract over concrete implementation without (ab)using type classes.

Constructors

KVStore 

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

encodeValue Source #

Arguments

:: a

value to encode

-> Text

textual representation

Encodes value into textual representation.

decodeValue Source #

Arguments

:: Text

value to decode

-> Maybe a

decoded value (if available)

Decodes value from textual representation.

Instances

Instances details
ValueCodec Text Source # 
Instance details

Defined in Headroom.IO.KVStore

ValueCodec UTCTime Source # 
Instance details

Defined in Headroom.IO.KVStore

Data Types

newtype ValueKey a Source #

Type-safe representation of the key for specific value.

Constructors

ValueKey Text 

Instances

Instances details
Eq (ValueKey a) Source # 
Instance details

Defined in Headroom.IO.KVStore

Methods

(==) :: ValueKey a -> ValueKey a -> Bool #

(/=) :: ValueKey a -> ValueKey a -> Bool #

Show (ValueKey a) Source # 
Instance details

Defined in Headroom.IO.KVStore

Methods

showsPrec :: Int -> ValueKey a -> ShowS #

show :: ValueKey a -> String #

showList :: [ValueKey a] -> ShowS #

newtype StorePath Source #

Path to the store (e.g. path of the SQLite database on filesystem).

Constructors

StorePath Text 

Instances

Instances details
Eq StorePath Source # 
Instance details

Defined in Headroom.IO.KVStore

Show StorePath Source # 
Instance details

Defined in Headroom.IO.KVStore

Public Functions

inMemoryKVStore :: MonadIO m => m (KVStore m) Source #

Constructs non-persistent in-memory instance of KVStore.

sqliteKVStore Source #

Arguments

:: MonadIO m 
=> StorePath

path of the store location

-> KVStore m

store instance

Constructs persistent instance of KVStore that uses SQLite as a backend.

valueKey :: Text -> ValueKey a Source #

Constructor function for ValueKey.