File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
test/Test/Cardano/Db/Mock/Unit/Conway/Config Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change 2
2
{-# LANGUAGE DataKinds #-}
3
3
{-# LANGUAGE FlexibleContexts #-}
4
4
{-# LANGUAGE KindSignatures #-}
5
+ {-# LANGUAGE OverloadedStrings #-}
5
6
{-# LANGUAGE ScopedTypeVariables #-}
6
7
{-# LANGUAGE TypeApplications #-}
7
8
@@ -280,10 +281,15 @@ queryConsumedTxOutCount ::
280
281
forall (a :: Db. TxOutTableType ) io .
281
282
(MonadIO io , Db. TxOutFields a ) =>
282
283
ReaderT SqlBackend io Word64
284
+ queryConsumedTxOutCount :: MonadIO io => ReaderT SqlBackend io Word64
283
285
queryConsumedTxOutCount = do
284
- res <- selectOne $ do
285
- txOut <- from $ table @ (Db. TxOutTable a )
286
- where_ (not_ $ isNothing_ $ txOut ^. Db. txOutConsumedByTxIdField @ a )
287
- pure countRows
288
-
289
- pure $ maybe 0 unValue res
286
+ maybe 0 unSingle . head <$> rawSql @ (Single Word64 ) q []
287
+ where
288
+ -- tx_out.consumed_by_tx_id may or may not exist, depending on the runtime configuration!
289
+ -- We use an obscure trick to avoid the error `column "consumed_by_tx_id" does not exist`
290
+ q =
291
+ " select count "
292
+ <> " from (select null as consumed_by_tx_id)"
293
+ <> " cross join lateral ("
294
+ <> " select count(*) from tx_out where consumed_by_tx_id is not null"
295
+ <> " ) as count"
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ consumeTx =
42
42
-- Should not have consumed_by_tx
43
43
assertEqBackoff
44
44
dbSync
45
- ( Query. queryConsumedTxOutCount @ 'Db. TxOutCore )
45
+ Query. queryConsumedTxOutCount
46
46
0
47
47
[]
48
48
" Unexpected consumed_by_tx count"
@@ -72,7 +72,7 @@ consumeTxConsumed =
72
72
-- Should have consumed_by_tx
73
73
assertEqBackoff
74
74
dbSync
75
- ( Query. queryConsumedTxOutCount @ 'Db. TxOutCore )
75
+ Query. queryConsumedTxOutCount
76
76
2
77
77
[]
78
78
" Unexpected consumed_by_tx count"
You can’t perform that action at this time.
0 commit comments