File tree 3 files changed +19
-9
lines changed
3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change 1
1
module Database.Query where
2
2
3
3
import Cardano.Slotting.Slot (SlotNo )
4
+ import Control.Monad.IO.Unlift (MonadUnliftIO , withRunInIO )
4
5
import Data.Profunctor.Product.Default (Default )
5
6
import Database.Orphans ()
6
7
import Database.PostgreSQL.Simple (Connection )
@@ -92,13 +93,16 @@ selectSerialisedScriptsBatch conn count =
92
93
pure serialised
93
94
94
95
withScriptEvaluationEvents
95
- :: Connection
96
+ :: (MonadUnliftIO m )
97
+ => Connection
96
98
-> a
97
- -> (a -> ScriptEvaluationRecord -> IO a )
98
- -> IO a
99
+ -> (a -> ScriptEvaluationRecord -> m a )
100
+ -> m a
99
101
withScriptEvaluationEvents conn a f = do
100
102
let select = selectTable scriptEvaluations
101
- runSelectFold conn select a f
103
+ withRunInIO \ runInIO ->
104
+ runSelectFold conn select a \ accum record ->
105
+ runInIO (f accum record)
102
106
103
107
insertScriptEvaluationEvents
104
108
:: (Default ToFields EvaluationEventRecord WriteEvaluationEventRecordFields )
Original file line number Diff line number Diff line change 3
3
module Evaluate where
4
4
5
5
import Codec.Serialise (deserialise )
6
+ import Control.Monad.IO.Unlift (MonadUnliftIO )
6
7
import Control.Monad.Trans.Except (runExceptT )
7
8
import Control.Monad.Trans.Writer (WriterT (runWriterT ))
8
9
import Data.ByteString qualified as BSL
@@ -35,20 +36,23 @@ data ScriptEvaluationInput = MkScriptEvaluationInput
35
36
}
36
37
37
38
evaluateScripts
38
- :: Postgres. Connection
39
+ :: (MonadFail m , MonadUnliftIO m )
40
+ => Postgres. Connection
39
41
-- ^ Database connection
40
42
-> a
41
43
-- ^ Initial accumulator
42
- -> (ScriptEvaluationInput -> a -> IO a )
44
+ -> (ScriptEvaluationInput -> a -> m a )
43
45
-- ^ Accumulation function
44
- -> IO a
46
+ -> m a
45
47
evaluateScripts conn initialAccum accumulate =
46
48
Db. withScriptEvaluationEvents conn initialAccum \ accum record -> do
47
49
scriptInput <- inputFromRecord record
48
50
accumulate scriptInput accum
49
51
50
52
inputFromRecord
51
- :: (MonadFail m ) => Db. ScriptEvaluationRecord -> m ScriptEvaluationInput
53
+ :: (MonadFail m )
54
+ => Db. ScriptEvaluationRecord
55
+ -> m ScriptEvaluationInput
52
56
inputFromRecord MkScriptEvaluationRecord' {.. } = do
53
57
let mkEvalCtx f =
54
58
runExceptT (runWriterT f) >>= \ case
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ library
110
110
, string-interpolate ^>= 0.3
111
111
, text
112
112
, transformers
113
+ , unliftio-core
113
114
, vector
114
115
115
116
executable dump-script-events
@@ -158,5 +159,6 @@ executable evaluate-scripts
158
159
ghc-options : -threaded -rtsopts
159
160
other-modules : Options
160
161
build-depends :
161
- , cardano-api ^>= 10.4
162
+ , cardano-api ^>= 10.4
162
163
, text
164
+ , unliftio-core
You can’t perform that action at this time.
0 commit comments