packages feed

eventful-sql-common 0.1.1 → 0.1.2

raw patch · 5 files changed

+25/−7 lines, 5 filesdep −splitdep ~eventful-corePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies removed: split

Dependency ranges changed: eventful-core

API changes (from Hackage documentation)

- Eventful.Store.Sql.Operations: sqlStoreEvents :: (MonadIO m, PersistEntity entity, PersistEntityBackend entity ~ SqlBackend) => SqlEventStoreConfig entity serialized -> (DBName -> DBName -> DBName -> Text) -> UUID -> [serialized] -> SqlPersistT m ()
+ Eventful.Store.Sql.Operations: sqlStoreEvents :: (MonadIO m, PersistEntity entity, PersistEntityBackend entity ~ SqlBackend) => SqlEventStoreConfig entity serialized -> Maybe (Text -> Text) -> (DBName -> DBName -> DBName -> Text) -> UUID -> [serialized] -> SqlPersistT m ()

Files

eventful-sql-common.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           eventful-sql-common-version:        0.1.1+version:        0.1.2 synopsis:       Common library for SQL event stores description:    Common library for SQL event stores category:       Database,Eventsourcing@@ -23,7 +23,6 @@ library   hs-source-dirs:       src-  default-extensions: ConstraintKinds DeriveFunctor DeriveGeneric FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving MultiParamTypeClasses OverloadedStrings QuasiQuotes RankNTypes RecordWildCards ScopedTypeVariables StandaloneDeriving TemplateHaskell TupleSections TypeFamilies   ghc-options: -Wall   build-depends:       base >= 4.9 && < 5@@ -33,7 +32,6 @@     , mtl     , persistent     , persistent-template-    , split     , text     , uuid   exposed-modules:
src/Eventful/Store/Sql/DefaultEntity.hs view
@@ -1,4 +1,8 @@+{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeFamilies #-}  -- | Definition for a default Entity to use with a SQL event store. 
src/Eventful/Store/Sql/JSONString.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE OverloadedStrings #-}+ module Eventful.Store.Sql.JSONString   ( JSONString   , jsonStringSerializer
src/Eventful/Store/Sql/Operations.hs view
@@ -1,3 +1,8 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-}+ module Eventful.Store.Sql.Operations   ( SqlEventStoreConfig (..)   , sqlGloballyOrderedEventStore@@ -8,6 +13,7 @@   ) where  import Control.Monad.Reader+import Data.Foldable (for_) import Data.Maybe (listToMaybe, maybe) import Data.Monoid ((<>)) import Data.Text (Text)@@ -46,9 +52,9 @@ sqlEventToGloballyOrdered   :: SqlEventStoreConfig entity serialized   -> Entity entity-  -> GloballyOrderedEvent (StoredEvent serialized)+  -> GloballyOrderedEvent serialized sqlEventToGloballyOrdered config@SqlEventStoreConfig{..} (Entity key event) =-  GloballyOrderedEvent (sqlEventStoreConfigUnKey key) $ sqlEventToStored config event+  storedEventToGloballyOrderedEvent (sqlEventStoreConfigUnKey key) (sqlEventToStored config event)  sqlEventToStored   :: SqlEventStoreConfig entity serialized@@ -88,7 +94,7 @@   :: (MonadIO m, PersistEntity entity, PersistEntityBackend entity ~ SqlBackend)   => SqlEventStoreConfig entity serialized   -> SequenceNumber-  -> SqlPersistT m [GloballyOrderedEvent (StoredEvent serialized)]+  -> SqlPersistT m [GloballyOrderedEvent serialized] sqlGetAllEventsFromSequence config@SqlEventStoreConfig{..} seqNum = do   entities <-     selectList@@ -113,11 +119,17 @@ sqlStoreEvents   :: (MonadIO m, PersistEntity entity, PersistEntityBackend entity ~ SqlBackend)   => SqlEventStoreConfig entity serialized+  -> Maybe (Text -> Text)   -> (DBName -> DBName -> DBName -> Text)   -> UUID   -> [serialized]   -> SqlPersistT m ()-sqlStoreEvents config@SqlEventStoreConfig{..} maxVersionSql uuid events = do+sqlStoreEvents config@SqlEventStoreConfig{..} mLockCommand maxVersionSql uuid events = do   versionNum <- sqlMaxEventVersion config maxVersionSql uuid   let entities = zipWith (sqlEventStoreConfigSequenceMakeEntity uuid) [versionNum + 1..] events+  -- NB: We need to take a lock on the events table or else the global sequence+  -- numbers may not increase monotonically over time.+  for_ mLockCommand $ \lockCommand -> rawExecute (lockCommand tableName) []   insertMany_ entities+  where+    (DBName tableName) = tableDBName (sqlEventStoreConfigSequenceMakeEntity nil 0 undefined)
src/Eventful/Store/Sql/Orphans.hs view
@@ -1,4 +1,5 @@ {-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE OverloadedStrings #-}  module Eventful.Store.Sql.Orphans   (