5
5
6
6
module Cardano.Db.Operations.Other.JsonbQuery where
7
7
8
- import Cardano.Db.Error (DbError (.. ), AsDbError (.. ))
9
- import Cardano.Db.Types (mkCallSite , DbAction )
10
- import Cardano.Prelude (ExceptT , MonadError (.. ), forM , traverse_ , MonadIO , forM_ )
11
8
import Control.Monad.IO.Class (liftIO )
12
-
13
9
import Data.ByteString (ByteString )
14
10
import Data.Int (Int64 )
15
11
import qualified Hasql.Connection as HsqlC
@@ -19,35 +15,9 @@ import qualified Hasql.Session as HsqlS
19
15
import qualified Hasql.Statement as HsqlS
20
16
import qualified Hasql.Transaction as HsqlT
21
17
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_ )
51
21
52
22
enableJsonbInSchema :: HsqlT. Transaction ()
53
23
enableJsonbInSchema = do
@@ -72,7 +42,6 @@ enableJsonbInSchema = do
72
42
, (" off_chain_vote_data" , " json" )
73
43
]
74
44
75
-
76
45
disableJsonbInSchema :: HsqlT. Transaction ()
77
46
disableJsonbInSchema = do
78
47
forM_ stmts $ \ (t, c) -> HsqlT. statement () (disableJsonbInSchemaStmt t c)
@@ -94,35 +63,6 @@ disableJsonbInSchema = do
94
63
, (" off_chain_vote_data" , " json" )
95
64
]
96
65
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
-
126
66
queryJsonbInSchemaExists :: AsDbError e => HsqlC. Connection -> ExceptT e IO Bool
127
67
queryJsonbInSchemaExists conn = do
128
68
result <- liftIO $ HsqlS. run (HsqlS. statement () jsonbSchemaStatement) conn
0 commit comments