Skip to content

Commit 89285ee

Browse files
committed
devide queries and use statements
1 parent a01778e commit 89285ee

36 files changed

+4693
-4795
lines changed

cardano-db-sync/src/Cardano/DbSync/Api.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import qualified Data.Strict.Maybe as Strict
8989
import Data.Time.Clock (getCurrentTime)
9090
import Database.Persist.Postgresql (ConnectionString)
9191
import Database.Persist.Sql (SqlBackend)
92+
import qualified Hasql.Connection as HqlC
9293
import Ouroboros.Consensus.Block.Abstract (BlockProtocol, HeaderHash, Point (..), fromRawHash)
9394
import Ouroboros.Consensus.BlockchainTime.WallClock.Types (SystemStart (..))
9495
import Ouroboros.Consensus.Config (SecurityParam (..), TopLevelConfig, configSecurityParam)
@@ -98,7 +99,6 @@ import Ouroboros.Consensus.Protocol.Abstract (ConsensusProtocol)
9899
import Ouroboros.Network.Block (BlockNo (..), Point (..))
99100
import Ouroboros.Network.Magic (NetworkMagic (..))
100101
import qualified Ouroboros.Network.Point as Point
101-
import qualified Hasql.Connection as HqlC
102102

103103
setConsistentLevel :: SyncEnv -> ConsistentLevel -> IO ()
104104
setConsistentLevel env cst = do
@@ -192,10 +192,10 @@ runAddJsonbToSchema :: SyncEnv -> IO ()
192192
runAddJsonbToSchema syncEnv =
193193
void $ DB.runDbIohkNoLogging (envDbEnv syncEnv) DB.enableJsonbInSchema
194194

195-
runRemoveJsonbFromSchema
196-
:: (MonadIO m, AsDbError e)
197-
=> SyncEnv
198-
-> DbAction e m ()
195+
runRemoveJsonbFromSchema ::
196+
(MonadIO m, AsDbError e) =>
197+
SyncEnv ->
198+
DbAction e m ()
199199
runRemoveJsonbFromSchema syncEnv = do
200200
DB.runDbT DB.Write transx
201201
where

cardano-db-sync/src/Cardano/DbSync/Database.hs

+3-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ data NextState
3838
| Done
3939
deriving (Eq)
4040

41-
4241
runDbThread ::
4342
SyncEnv ->
4443
MetricSetters ->
@@ -76,8 +75,8 @@ runDbThread syncEnv metricsSetters queue = do
7675
-- Handle the result of running the actions
7776
case result of
7877
Left err -> logError tracer $ "Error: " <> show err
79-
Right Continue -> processQueue -- Continue processing
80-
Right Done -> pure () -- Stop processing
78+
Right Continue -> processQueue -- Continue processing
79+
Right Done -> pure () -- Stop processing
8180

8281
-- Handle the case where the syncing thread has restarted
8382
handleRestart :: TMVar (LatestPoints, CurrentTip) -> IO ()
@@ -87,7 +86,7 @@ runDbThread syncEnv metricsSetters queue = do
8786
currentTip <- getCurrentTipBlockNo syncEnv
8887
logDbState syncEnv
8988
atomically $ putTMVar resultVar (latestPoints, currentTip)
90-
processQueue -- Continue processing
89+
processQueue -- Continue processing
9190

9291
-- Update block and slot height metrics
9392
updateBlockMetrics :: IO ()
@@ -97,7 +96,6 @@ runDbThread syncEnv metricsSetters queue = do
9796
setDbBlockHeight metricsSetters $ bBlockNo block
9897
setDbSlotHeight metricsSetters $ bSlotNo block
9998

100-
10199
-- runDbThread ::
102100
-- SyncEnv ->
103101
-- MetricSetters ->
@@ -138,7 +136,6 @@ runDbThread syncEnv metricsSetters queue = do
138136
-- atomically $ putTMVar resultVar (latestPoints, currentTip)
139137
-- loop
140138

141-
142139
-- | Run the list of 'DbAction's. Block are applied in a single set (as a transaction)
143140
-- and other operations are applied one-by-one.
144141
runActions ::

cardano-db/cardano-db.cabal

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ library
102102
, filepath
103103
, file-embed
104104
, hasql
105-
, hasql-transaction
106105
, iohk-monitoring
107106
, lifted-base
108107
, memory

cardano-db/src/Cardano/Db/Error.hs

+42-41
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,74 @@
1-
{-# LANGUAGE DeriveGeneric #-}
2-
{-# LANGUAGE LambdaCase #-}
3-
{-# LANGUAGE OverloadedStrings #-}
41
{-# LANGUAGE RankNTypes #-}
52

63
module Cardano.Db.Error (
7-
AsDbError (..),
4+
-- AsDbError (..),
85
CallSite (..),
96
DbError (..),
107
runOrThrowIODb,
118
runOrThrowIO,
129
logAndThrowIO,
13-
base16encode
10+
base16encode,
1411
) where
1512

1613
import Cardano.BM.Trace (Trace, logError)
17-
import Cardano.Db.Schema.Ids
18-
import Cardano.Prelude (throwIO, MonadIO)
14+
import Cardano.Prelude (MonadIO, throwIO)
1915
import Control.Exception (Exception)
16+
import qualified Data.ByteString.Base16 as Base16
2017
import Data.ByteString.Char8 (ByteString)
2118
import Data.Text (Text)
22-
import Data.Word (Word16, Word64)
23-
import GHC.Generics (Generic)
24-
import qualified Data.ByteString.Base16 as Base16
2519
import qualified Data.Text.Encoding as Text
26-
import qualified Hasql.Session as HsqlS
2720

28-
class AsDbError e where
29-
toDbError :: DbError -> e
30-
fromDbError :: e -> Maybe DbError
21+
import qualified Hasql.Session as HsqlSes
3122

32-
data DbError
33-
= DbError !CallSite !Text !HsqlS.SessionError
34-
| DbLookupError !CallSite !Text !LookupContext
35-
deriving (Show, Eq)
23+
data DbError = DbError
24+
{ dbErrorCallSite :: !CallSite
25+
, dbErrorMessage :: !Text
26+
, dbErrorCause :: !(Maybe HsqlSes.SessionError) -- Now a Maybe
27+
}
28+
29+
-- class AsDbError e where
30+
-- toDbError :: DbError -> e
31+
-- fromDbError :: e -> Maybe DbError
32+
33+
-- data DbError
34+
-- = DbError !CallSite !Text !HsqlS.SessionError
35+
-- | DbLookupError !CallSite !Text !LookupContext
36+
-- deriving (Show, Eq)
3637

37-
instance Exception DbError
38+
-- instance Exception DbError
3839

3940
data CallSite = CallSite
4041
{ csModule :: !Text
4142
, csFile :: !Text
4243
, csLine :: !Int
43-
} deriving (Show, Eq)
44-
45-
data LookupContext
46-
= BlockHashContext !ByteString
47-
| BlockIdContext !Word64
48-
| MessageContext !Text
49-
| TxHashContext !ByteString
50-
| TxOutPairContext !ByteString !Word16
51-
| EpochNoContext !Word64
52-
| SlotNoContext !Word64
53-
| GovActionPairContext !TxId !Word64
54-
| MetaEmptyContext
55-
| MetaMultipleRowsContext
56-
| MultipleGenesisContext
57-
| ExtraMigrationContext !String
58-
| PruneConsumedContext !String
59-
| RJsonbInSchemaContext !String
60-
| TxOutVariantContext !String
61-
deriving (Show, Eq, Generic)
62-
63-
instance Exception LookupContext
44+
}
45+
deriving (Show, Eq)
46+
47+
-- data LookupContext
48+
-- = BlockHashContext !ByteString
49+
-- | BlockIdContext !Word64
50+
-- | MessageContext !Text
51+
-- | TxHashContext !ByteString
52+
-- | TxOutPairContext !ByteString !Word16
53+
-- | EpochNoContext !Word64
54+
-- | SlotNoContext !Word64
55+
-- | GovActionPairContext !TxId !Word64
56+
-- | MetaEmptyContext
57+
-- | MetaMultipleRowsContext
58+
-- | MultipleGenesisContext
59+
-- | ExtraMigrationContext !String
60+
-- | PruneConsumedContext !String
61+
-- | RJsonbInSchemaContext !String
62+
-- | TxOutVariantContext !String
63+
-- deriving (Show, Eq, Generic)
64+
65+
-- instance Exception LookupContext
6466

6567
-- catchDbError :: String -> HsqlT.Transaction a -> HsqlT.Transaction a
6668
-- catchDbError context action =
6769
-- action `catch` \e ->
6870
-- throwError $ DbError $ context ++ ": " ++ show e
6971

70-
7172
-- instance Show LookupFail where
7273
-- show =
7374
-- \case

0 commit comments

Comments
 (0)