eventium-sql-common 0.3.2 → 0.4.0
raw patch · 2 files changed
+13/−11 lines, 2 filesdep ~eventium-core
Dependency ranges changed: eventium-core
Files
eventium-sql-common.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: eventium-sql-common-version: 0.3.2+version: 0.4.0 synopsis: Common library for SQL event stores description: Eventium-sql-common provides shared utilities and abstractions for SQL-based event stores. It includes Persistent entity definitions, JSON serialization helpers, and common database@@ -51,7 +51,7 @@ aeson >=1.5 && <2.3 , base >=4.9 && <5 , bytestring >=0.10 && <0.13- , eventium-core >=0.3.0 && <0.4.0+ , eventium-core >=0.4.0 && <0.5.0 , mtl >=2.2 && <2.4 , persistent >=2.14 && <2.18 , text >=1.2 && <2.2
src/Eventium/Store/Sql/Operations.hs view
@@ -155,15 +155,16 @@ (FieldNameDB -> FieldNameDB -> FieldNameDB -> Text) -> UUID -> [serialized] ->- SqlPersistT m EventVersion+ SqlPersistT m EventWriteResult sqlStoreEvents config mLockCommand maxVersionSql uid events = do versionNum <- sqlMaxEventVersion config maxVersionSql uid- let entities = zipWith (\v e -> config.sequenceMakeEntity uid v e Nothing) [versionNum + 1 ..] events+ let vers = take (length events) [versionNum + 1 ..]+ entities = zipWith (\v e -> config.sequenceMakeEntity uid v e Nothing) vers 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- return $ versionNum + EventVersion (length events)+ keys <- insertMany entities+ return $ zip vers (map config.unKey keys) where tableName = unEntityNameDB $ tableDBName (config.sequenceMakeEntity nil 0 undefined Nothing) @@ -176,10 +177,11 @@ (FieldNameDB -> FieldNameDB -> FieldNameDB -> Text) -> UUID -> [TaggedEvent serialized] ->- SqlPersistT m EventVersion+ SqlPersistT m EventWriteResult sqlStoreEventsTagged config mLockCommand maxVersionSql uid taggedEvents = do versionNum <- sqlMaxEventVersion config maxVersionSql uid- let entities =+ let vers = take (length taggedEvents) [versionNum + 1 ..]+ entities = zipWith ( \v (TaggedEvent meta e) -> config.sequenceMakeEntity@@ -188,11 +190,11 @@ e (Just $ encodeJSON meta) )- [versionNum + 1 ..]+ vers taggedEvents for_ mLockCommand $ \lockCommand -> rawExecute (lockCommand tableName) []- _ <- insertMany entities- return $ versionNum + EventVersion (length taggedEvents)+ keys <- insertMany entities+ return $ zip vers (map config.unKey keys) where tableName = unEntityNameDB $ tableDBName (config.sequenceMakeEntity nil 0 undefined Nothing)