55
66module Cardano.Db.Operations.Other.JsonbQuery where
77
8- import Cardano.Db.Error (DbError (.. ), AsDbError (.. ))
9- import Cardano.Db.Types (mkCallSite , DbAction )
10- import Cardano.Prelude (ExceptT , MonadError (.. ), forM , traverse_ , MonadIO , forM_ )
118import Control.Monad.IO.Class (liftIO )
12-
139import Data.ByteString (ByteString )
1410import Data.Int (Int64 )
1511import qualified Hasql.Connection as HsqlC
@@ -19,35 +15,9 @@ import qualified Hasql.Session as HsqlS
1915import qualified Hasql.Statement as HsqlS
2016import qualified Hasql.Transaction as HsqlT
2117
22-
23- -- enableJsonbInSchema :: AsDbError e => HsqlC.Connection -> ExceptT e IO ()
24- -- enableJsonbInSchema conn = do
25- -- results <- forM stmts (\stmt -> liftIO $ HsqlS.run (HasqlS.statement () (enableJsonbInSchemaStmt stmt)) conn)
26- -- traverse_ handleResult results
27- -- where
28- -- enableJsonbInSchemaStmt :: (ByteString, ByteString) -> HsqlS.Statement () ()
29- -- enableJsonbInSchemaStmt (t, c) =
30- -- HsqlS.Statement
31- -- ("ALTER TABLE " <> t <> " ALTER COLUMN " <> c <> " TYPE jsonb USING " <> c <> "::jsonb")
32- -- HsqlE.noParams
33- -- HsqlD.noResult
34- -- True
35-
36- -- handleResult res =
37- -- case res of
38- -- Left err -> throwError $ toDbError $ QueryError "enableJsonbInSchema" mkCallSite err
39- -- Right _ -> pure ()
40-
41- -- stmts :: [(ByteString, ByteString)]
42- -- stmts = [ ("tx_metadata", "json")
43- -- , ("script", "json")
44- -- , ("datum", "value")
45- -- , ("redeemer_data", "value")
46- -- , ("cost_model", "costs")
47- -- , ("gov_action_proposal", "description")
48- -- , ("off_chain_pool_data", "json")
49- -- , ("off_chain_vote_data", "json")
50- -- ]
18+ import Cardano.Db.Error (DbError (.. ), AsDbError (.. ))
19+ import Cardano.Db.Statement.Function.Core (mkCallSite )
20+ import Cardano.Prelude (ExceptT , MonadError (.. ), forM_ )
5121
5222enableJsonbInSchema :: HsqlT. Transaction ()
5323enableJsonbInSchema = do
@@ -72,7 +42,6 @@ enableJsonbInSchema = do
7242 , (" off_chain_vote_data" , " json" )
7343 ]
7444
75-
7645disableJsonbInSchema :: HsqlT. Transaction ()
7746disableJsonbInSchema = do
7847 forM_ stmts $ \ (t, c) -> HsqlT. statement () (disableJsonbInSchemaStmt t c)
@@ -94,35 +63,6 @@ disableJsonbInSchema = do
9463 , (" off_chain_vote_data" , " json" )
9564 ]
9665
97- -- disableJsonbInSchema' :: (MonadIO m, AsDbError e) => HsqlC.Connection -> DbAction e m ()
98- -- disableJsonbInSchema' conn = do
99- -- results <- forM stmts (\stmt -> liftIO $ HsqlS.run (statement () (disableJsonbInSchemaStmt stmt)) conn)
100- -- traverse_ handleResult results
101- -- where
102- -- disableJsonbInSchemaStmt :: (ByteString, ByteString) -> HsqlS.Statement () ()
103- -- disableJsonbInSchemaStmt (t, c) =
104- -- HsqlS.Statement
105- -- ("ALTER TABLE " <> t <> " ALTER COLUMN " <> c <> " TYPE VARCHAR")
106- -- HsqlE.noParams
107- -- HsqlD.noResult
108- -- True
109-
110- -- handleResult res =
111- -- case res of
112- -- Left err -> throwError $ toDbError $ QueryError "disableJsonbInSchema" mkCallSite err
113- -- Right _ -> pure ()
114-
115- -- stmts :: [(ByteString, ByteString)]
116- -- stmts = [ ("tx_metadata", "json")
117- -- , ("script", "json")
118- -- , ("datum", "value")
119- -- , ("redeemer_data", "value")
120- -- , ("cost_model", "costs")
121- -- , ("gov_action_proposal", "description")
122- -- , ("off_chain_pool_data", "json")
123- -- , ("off_chain_vote_data", "json")
124- -- ]
125-
12666queryJsonbInSchemaExists :: AsDbError e => HsqlC. Connection -> ExceptT e IO Bool
12767queryJsonbInSchemaExists conn = do
12868 result <- liftIO $ HsqlS. run (HsqlS. statement () jsonbSchemaStatement) conn
0 commit comments