Skip to content

Persistent to Hasql #1938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ repository cardano-haskell-packages
d4a35cd3121aa00d18544bb0ac01c3e1691d618f462c46129271bccf39f7e8ee

index-state:
, hackage.haskell.org 2024-10-10T00:52:24Z
, cardano-haskell-packages 2024-11-26T16:00:26Z
, hackage.haskell.org 2025-02-05T12:01:20Z
, cardano-haskell-packages 2025-02-04T11:56:25Z

packages:
cardano-db
Expand Down
32 changes: 16 additions & 16 deletions cardano-chain-gen/src/Cardano/Mock/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Prelude ()
queryVersionMajorFromEpoch ::
MonadIO io =>
Word64 ->
ReaderT SqlBackend io (Maybe Word16)
DB.DbAction io (Maybe Word16)
queryVersionMajorFromEpoch epochNo = do
res <- selectOne $ do
prop <- from $ table @Db.EpochParam
Expand All @@ -48,7 +48,7 @@ queryVersionMajorFromEpoch epochNo = do
queryParamProposalFromEpoch ::
MonadIO io =>
Word64 ->
ReaderT SqlBackend io (Maybe Db.ParamProposal)
DB.DbAction io (Maybe Db.ParamProposal)
queryParamProposalFromEpoch epochNo = do
res <- selectOne $ do
prop <- from $ table @Db.ParamProposal
Expand All @@ -59,7 +59,7 @@ queryParamProposalFromEpoch epochNo = do
queryParamFromEpoch ::
MonadIO io =>
Word64 ->
ReaderT SqlBackend io (Maybe Db.EpochParam)
DB.DbAction io (Maybe Db.EpochParam)
queryParamFromEpoch epochNo = do
res <- selectOne $ do
param <- from $ table @Db.EpochParam
Expand All @@ -68,22 +68,22 @@ queryParamFromEpoch epochNo = do
pure (entityVal <$> res)

-- | Query whether there any null tx deposits?
queryNullTxDepositExists :: MonadIO io => ReaderT SqlBackend io Bool
queryNullTxDepositExists :: MonadIO io => DB.DbAction io Bool
queryNullTxDepositExists = do
res <- select $ do
tx <- from $ table @Db.Tx
where_ $ isNothing_ (tx ^. Db.TxDeposit)
pure $ not (null res)

queryMultiAssetCount :: MonadIO io => ReaderT SqlBackend io Word
queryMultiAssetCount :: MonadIO io => DB.DbAction io Word
queryMultiAssetCount = do
res <- select $ do
_ <- from (table @Db.MultiAsset)
pure countRows

pure $ maybe 0 unValue (listToMaybe res)

queryTxMetadataCount :: MonadIO io => ReaderT SqlBackend io Word
queryTxMetadataCount :: MonadIO io => DB.DbAction io Word
queryTxMetadataCount = do
res <- selectOne $ do
_ <- from (table @Db.TxMetadata)
Expand All @@ -95,7 +95,7 @@ queryDRepDistrAmount ::
MonadIO io =>
ByteString ->
Word64 ->
ReaderT SqlBackend io Word64
DB.DbAction io Word64
queryDRepDistrAmount drepHash epochNo = do
res <- selectOne $ do
(distr :& hash) <-
Expand All @@ -113,7 +113,7 @@ queryDRepDistrAmount drepHash epochNo = do

queryGovActionCounts ::
MonadIO io =>
ReaderT SqlBackend io (Word, Word, Word, Word)
DB.DbAction io (Word, Word, Word, Word)
queryGovActionCounts = do
ratified <- countNonNulls Db.GovActionProposalRatifiedEpoch
enacted <- countNonNulls Db.GovActionProposalEnactedEpoch
Expand All @@ -125,7 +125,7 @@ queryGovActionCounts = do
countNonNulls ::
(MonadIO io, PersistField field) =>
EntityField Db.GovActionProposal (Maybe field) ->
ReaderT SqlBackend io Word
DB.DbAction io Word
countNonNulls field = do
res <- selectOne $ do
e <- from $ table @Db.GovActionProposal
Expand All @@ -137,7 +137,7 @@ queryGovActionCounts = do
queryConstitutionAnchor ::
MonadIO io =>
Word64 ->
ReaderT SqlBackend io (Maybe (Text, ByteString))
DB.DbAction io (Maybe (Text, ByteString))
queryConstitutionAnchor epochNo = do
res <- selectOne $ do
(_ :& anchor :& epochState) <-
Expand All @@ -160,7 +160,7 @@ queryConstitutionAnchor epochNo = do

queryRewardRests ::
MonadIO io =>
ReaderT SqlBackend io [(Db.RewardSource, Word64)]
DB.DbAction io [(Db.RewardSource, Word64)]
queryRewardRests = do
res <- select $ do
reward <- from $ table @Db.RewardRest
Expand All @@ -170,7 +170,7 @@ queryRewardRests = do

queryTreasuryDonations ::
MonadIO io =>
ReaderT SqlBackend io Word64
DB.DbAction io Word64
queryTreasuryDonations = do
res <- selectOne $ do
txs <- from $ table @Db.Tx
Expand All @@ -183,7 +183,7 @@ queryVoteCounts ::
MonadIO io =>
ByteString ->
Word16 ->
ReaderT SqlBackend io (Word64, Word64, Word64)
DB.DbAction io (Word64, Word64, Word64)
queryVoteCounts txHash idx = do
yes <- countVotes Db.VoteYes
no <- countVotes Db.VoteNo
Expand All @@ -210,7 +210,7 @@ queryVoteCounts txHash idx = do
queryEpochStateCount ::
MonadIO io =>
Word64 ->
ReaderT SqlBackend io Word64
DB.DbAction io Word64
queryEpochStateCount epochNo = do
res <- selectOne $ do
epochState <- from (table @Db.EpochState)
Expand All @@ -222,7 +222,7 @@ queryEpochStateCount epochNo = do
queryCommitteeByTxHash ::
MonadIO io =>
ByteString ->
ReaderT SqlBackend io (Maybe Db.Committee)
DB.DbAction io (Maybe Db.Committee)
queryCommitteeByTxHash txHash = do
res <- selectOne $ do
(committee :& _ :& tx) <-
Expand All @@ -244,7 +244,7 @@ queryCommitteeByTxHash txHash = do
queryCommitteeMemberCountByTxHash ::
MonadIO io =>
Maybe ByteString ->
ReaderT SqlBackend io Word64
DB.DbAction io Word64
queryCommitteeMemberCountByTxHash txHash = do
res <- selectOne $ do
(_ :& committee :& _ :& tx) <-
Expand Down
16 changes: 8 additions & 8 deletions cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module Test.Cardano.Db.Mock.Config (
withCustomConfigAndLogs,
withFullConfig',
replaceConfigFile,
txOutTableTypeFromConfig,
txOutVariantTypeFromConfig,
) where

import Cardano.Api (NetworkMagic (..))
Expand Down Expand Up @@ -226,13 +226,13 @@ withDBSyncEnv mkEnv = bracket mkEnv stopDBSyncIfRunning
getDBSyncPGPass :: DBSyncEnv -> DB.PGPassSource
getDBSyncPGPass = enpPGPassSource . dbSyncParams

queryDBSync :: DBSyncEnv -> ReaderT SqlBackend (NoLoggingT IO) a -> IO a
queryDBSync :: DBSyncEnv -> DB.DbAction (NoLoggingT IO) a -> IO a
queryDBSync env = DB.runWithConnectionNoLogging (getDBSyncPGPass env)

getPoolLayer :: DBSyncEnv -> IO PoolDataLayer
getPoolLayer env = do
pgconfig <- runOrThrowIO $ DB.readPGPass (enpPGPassSource $ dbSyncParams env)
pool <- runNoLoggingT $ createPostgresqlPool (DB.toConnectionString pgconfig) 1 -- Pool size of 1 for tests
pool <- runNoLoggingT $ createPostgresqlPool (DB.toConnectionSetting pgconfig) 1 -- Pool size of 1 for tests
pure $
postgresqlPoolDataLayer
nullTracer
Expand Down Expand Up @@ -601,14 +601,14 @@ replaceConfigFile newFilename dbSync@DBSyncEnv {..} = do
newParams =
dbSyncParams {enpConfigFile = ConfigFile $ configDir </> newFilename}

txOutTableTypeFromConfig :: DBSyncEnv -> DB.TxOutTableType
txOutTableTypeFromConfig dbSyncEnv =
txOutVariantTypeFromConfig :: DBSyncEnv -> DB.TxOutVariantType
txOutVariantTypeFromConfig dbSyncEnv =
case sioTxOut $ dncInsertOptions $ dbSyncConfig dbSyncEnv of
TxOutDisable -> DB.TxOutCore
TxOutDisable -> DB.TxOutVariantCore
TxOutEnable useTxOutAddress -> getTxOutTT useTxOutAddress
TxOutConsumed _ useTxOutAddress -> getTxOutTT useTxOutAddress
TxOutConsumedPrune _ useTxOutAddress -> getTxOutTT useTxOutAddress
TxOutConsumedBootstrap _ useTxOutAddress -> getTxOutTT useTxOutAddress
where
getTxOutTT :: UseTxOutAddress -> DB.TxOutTableType
getTxOutTT value = if unUseTxOutAddress value then DB.TxOutVariantAddress else DB.TxOutCore
getTxOutTT :: UseTxOutAddress -> DB.TxOutVariantType
getTxOutTT value = if unUseTxOutAddress value then DB.TxOutVariantAddress else DB.TxOutVariantCore
Loading
Loading