eventsourcing-0.9.0: CQRS/ES library.

Safe HaskellNone
LanguageHaskell2010

Database.CQRS.TabularData.Internal

Synopsis

Documentation

data Condition a where Source #

Constructors

Equal :: Eq a => a -> Condition a 
NotEqual :: Eq a => a -> Condition a 
LowerThan :: Ord a => a -> Condition a 
LowerThanOrEqual :: Ord a => a -> Condition a 
GreaterThan :: Ord a => a -> Condition a 
GreaterThanOrEqual :: Ord a => a -> Condition a 
Instances
Eq (Condition a) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

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

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

Show a => Show (Condition a) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

newtype Conditions a Source #

Constructors

Conditions 

Fields

Instances
Eq a => Wrapper Conditions a Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

wrap :: a -> Conditions a Source #

Eq (Conditions a) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

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

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

Show a => Show (Conditions a) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Semigroup (Conditions a) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Monoid (Conditions a) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

data Columns where Source #

Kind of types that describe columns of a table.

This is not intended as a type. It's promoted to a kind.

Use Flat for simple tables and WithUniqueKey if you want to be able to do upserts and/or store tuples in memory with a hash map instead of a list.

Constructors

Flat :: [(Symbol, Type)] -> Columns 
WithUniqueKey :: [(Symbol, Type)] -> [(Symbol, Type)] -> Columns 

type family Flatten (cols :: k) :: [(Symbol, Type)] where ... Source #

Equations

Flatten (WithUniqueKey (col ': keyCols) cols) = col ': Flatten (WithUniqueKey keyCols cols) 
Flatten (WithUniqueKey '[] cols) = cols 
Flatten (Flat cols) = cols 

type Tuple f cols = FlatTuple f (Flatten cols) Source #

A named tuple representing a row in the table.

data FlatTuple :: (Type -> Type) -> [(Symbol, Type)] -> Type where Source #

Constructors

Nil :: FlatTuple f '[] 
Cons :: f a -> FlatTuple f cols -> FlatTuple f ('(sym, a) ': cols) 
Instances
(Eq (f a), Eq (FlatTuple f cols)) => Eq (FlatTuple f ((,) sym a ': cols)) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

(==) :: FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) -> Bool #

(/=) :: FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) -> Bool #

Eq (FlatTuple f ([] :: [(Symbol, Type)])) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

(==) :: FlatTuple f [] -> FlatTuple f [] -> Bool #

(/=) :: FlatTuple f [] -> FlatTuple f [] -> Bool #

(Ord (f a), Ord (FlatTuple f cols)) => Ord (FlatTuple f ((,) sym a ': cols)) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

compare :: FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) -> Ordering #

(<) :: FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) -> Bool #

(<=) :: FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) -> Bool #

(>) :: FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) -> Bool #

(>=) :: FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) -> Bool #

max :: FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) #

min :: FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) #

Ord (FlatTuple f ([] :: [(Symbol, Type)])) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

compare :: FlatTuple f [] -> FlatTuple f [] -> Ordering #

(<) :: FlatTuple f [] -> FlatTuple f [] -> Bool #

(<=) :: FlatTuple f [] -> FlatTuple f [] -> Bool #

(>) :: FlatTuple f [] -> FlatTuple f [] -> Bool #

(>=) :: FlatTuple f [] -> FlatTuple f [] -> Bool #

max :: FlatTuple f [] -> FlatTuple f [] -> FlatTuple f [] #

min :: FlatTuple f [] -> FlatTuple f [] -> FlatTuple f [] #

(AllColumns Show cols, forall a. Show a => Show (f a)) => Show (FlatTuple f cols) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

showsPrec :: Int -> FlatTuple f cols -> ShowS #

show :: FlatTuple f cols -> String #

showList :: [FlatTuple f cols] -> ShowS #

(Semigroup (f a), Semigroup (FlatTuple f cols)) => Semigroup (FlatTuple f ((,) sym a ': cols)) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

(<>) :: FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) #

sconcat :: NonEmpty (FlatTuple f ((sym, a) ': cols)) -> FlatTuple f ((sym, a) ': cols) #

stimes :: Integral b => b -> FlatTuple f ((sym, a) ': cols) -> FlatTuple f ((sym, a) ': cols) #

Semigroup (FlatTuple f ([] :: [(Symbol, Type)])) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

(<>) :: FlatTuple f [] -> FlatTuple f [] -> FlatTuple f [] #

sconcat :: NonEmpty (FlatTuple f []) -> FlatTuple f [] #

stimes :: Integral b => b -> FlatTuple f [] -> FlatTuple f [] #

(Monoid (f a), Monoid (FlatTuple f xs)) => Monoid (FlatTuple f ((,) sym a ': xs)) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

mempty :: FlatTuple f ((sym, a) ': xs) #

mappend :: FlatTuple f ((sym, a) ': xs) -> FlatTuple f ((sym, a) ': xs) -> FlatTuple f ((sym, a) ': xs) #

mconcat :: [FlatTuple f ((sym, a) ': xs)] -> FlatTuple f ((sym, a) ': xs) #

Monoid (FlatTuple f ([] :: [(Symbol, Type)])) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

mempty :: FlatTuple f [] #

mappend :: FlatTuple f [] -> FlatTuple f [] -> FlatTuple f [] #

mconcat :: [FlatTuple f []] -> FlatTuple f [] #

(Hashable (f a), Hashable (FlatTuple f cols)) => Hashable (FlatTuple f ((,) sym a ': cols)) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

hashWithSalt :: Int -> FlatTuple f ((sym, a) ': cols) -> Int #

hash :: FlatTuple f ((sym, a) ': cols) -> Int #

Hashable (FlatTuple f ([] :: [(Symbol, Type)])) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

hashWithSalt :: Int -> FlatTuple f [] -> Int #

hash :: FlatTuple f [] -> Int #

pattern (:~) :: a -> FlatTuple Identity cols -> FlatTuple Identity ('(sym, a) ': cols) infixr 5 Source #

class Field f (sym :: Symbol) a (cols :: [(Symbol, Type)]) | cols sym -> a where Source #

Methods

cfield :: proxy sym -> f a -> FlatTuple f cols Source #

Instances
(Monoid (f b), Field f sym a cols) => Field f sym a ((,) sym' b ': cols) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

cfield :: proxy sym -> f a -> FlatTuple f ((sym', b) ': cols) Source #

Monoid (FlatTuple f cols) => Field f sym a ((,) sym a ': cols) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

cfield :: proxy sym -> f a -> FlatTuple f ((sym, a) ': cols) Source #

class Wrapper f a where Source #

Methods

wrap :: a -> f a Source #

Instances
Wrapper Update a Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

wrap :: a -> Update a Source #

Eq a => Wrapper Conditions a Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

wrap :: a -> Conditions a Source #

field :: forall cols sym f a. (Field f sym a (Flatten cols), Wrapper f a) => a -> Tuple f cols Source #

Create a tuple with the given field set to the given value wrapped into f. In practice, f is Conditions or Update.

It is meant to be used together with TypeApplications, e.g. field "field_name" value @

ffield :: forall cols sym f a. Field f sym a (Flatten cols) => f a -> Tuple f cols Source #

Create a tuple with the given field set to the given "wrapped" value.

It is more flexible than field but less convenient to use if the goal is to simply wrap the value inside the Applicative. In particular, it can be used with Conditions such as ffield "email" (equal "someoneexample.com")

class MergeSplitTuple keyCols cols where Source #

Methods

mergeTuple :: (FlatTuple f keyCols, FlatTuple f cols) -> Tuple f (WithUniqueKey keyCols cols) Source #

splitTuple :: Tuple f (WithUniqueKey keyCols cols) -> (FlatTuple f keyCols, FlatTuple f cols) Source #

Instances
MergeSplitTuple ([] :: [(Symbol, Type)]) cols Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

mergeTuple :: (FlatTuple f [], FlatTuple f cols) -> Tuple f (WithUniqueKey [] cols) Source #

splitTuple :: Tuple f (WithUniqueKey [] cols) -> (FlatTuple f [], FlatTuple f cols) Source #

MergeSplitTuple keyCols cols => MergeSplitTuple (a ': keyCols) cols Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

mergeTuple :: (FlatTuple f (a ': keyCols), FlatTuple f cols) -> Tuple f (WithUniqueKey (a ': keyCols) cols) Source #

splitTuple :: Tuple f (WithUniqueKey (a ': keyCols) cols) -> (FlatTuple f (a ': keyCols), FlatTuple f cols) Source #

type family AllColumns (cs :: Type -> Constraint) (cols :: [(Symbol, Type)]) :: Constraint where ... Source #

Equations

AllColumns _ '[] = () 
AllColumns cs ('(sym, a) ': cols) = (cs a, KnownSymbol sym, AllColumns cs cols) 

toList :: forall cs cols f b. AllColumns cs cols => (forall a. cs a => String -> f a -> b) -> FlatTuple f cols -> [b] Source #

Transform a tuple into a list of pairs given a function to transform the field values.

cs is some constraint that the values need to satisfy. For example, toList Show (name value -> (name, maybe NULL show (getLast value))) :: Tuple Last cols -> [(String, String)] @

class GetKeyAndConditions keyCols cols where Source #

Used to optimise operations on the in-memory storage. When we want to update or delete rows based on some conditions that would match one row matching its key, it's more efficient to use alter instead of traversing the hash map.

Instances
GetKeyAndConditions ([] :: [(Symbol, Type)]) cols Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

GetKeyAndConditions keyCols cols => GetKeyAndConditions ((,) sym a ': keyCols) cols Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

getKeyAndConditions :: Tuple Conditions (WithUniqueKey ((sym, a) ': keyCols) cols) -> Maybe (FlatTuple Identity ((sym, a) ': keyCols), FlatTuple Conditions cols) Source #

data Update a where Source #

Constructors

NoUpdate :: Update a 
Set :: a -> Update a 
Plus :: Num a => a -> Update a 
Minus :: Num a => a -> Update a 
Instances
Wrapper Update a Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

wrap :: a -> Update a Source #

Show a => Show (Update a) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

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

show :: Update a -> String #

showList :: [Update a] -> ShowS #

Semigroup (Update a) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

(<>) :: Update a -> Update a -> Update a #

sconcat :: NonEmpty (Update a) -> Update a #

stimes :: Integral b => b -> Update a -> Update a #

Monoid (Update a) Source # 
Instance details

Defined in Database.CQRS.TabularData.Internal

Methods

mempty :: Update a #

mappend :: Update a -> Update a -> Update a #

mconcat :: [Update a] -> Update a #