2020-12-08 17:22:31 +03:00
|
|
|
-- | Functions for fetching and updating @'Metadata' in the catalog.
|
2019-08-14 02:34:37 +03:00
|
|
|
module Hasura.RQL.DDL.Schema.Catalog
|
2020-12-08 17:22:31 +03:00
|
|
|
( fetchMetadataFromCatalog
|
|
|
|
, setMetadataInCatalog
|
2019-08-14 02:34:37 +03:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Hasura.Prelude
|
|
|
|
|
2020-10-27 16:53:49 +03:00
|
|
|
import qualified Database.PG.Query as Q
|
2019-09-19 07:47:36 +03:00
|
|
|
|
2020-10-27 16:53:49 +03:00
|
|
|
import Hasura.Backends.Postgres.Connection
|
2020-12-08 17:22:31 +03:00
|
|
|
import Hasura.RQL.Types.Error
|
|
|
|
import Hasura.RQL.Types.Metadata
|
2019-08-14 02:34:37 +03:00
|
|
|
|
2020-12-08 17:22:31 +03:00
|
|
|
fetchMetadataFromCatalog :: Q.TxE QErr Metadata
|
|
|
|
fetchMetadataFromCatalog = do
|
|
|
|
rows <- Q.withQE defaultTxErrorHandler
|
|
|
|
[Q.sql|
|
|
|
|
SELECT metadata from hdb_catalog.hdb_metadata where id = 1
|
|
|
|
|] () True
|
|
|
|
case rows of
|
|
|
|
[] -> pure emptyMetadata
|
|
|
|
[(Identity (Q.AltJ metadata))] -> pure metadata
|
|
|
|
_ -> throw500 "multiple rows in hdb_metadata table"
|
|
|
|
|
|
|
|
setMetadataInCatalog :: Metadata -> Q.TxE QErr ()
|
|
|
|
setMetadataInCatalog metadata =
|
|
|
|
Q.unitQE defaultTxErrorHandler
|
2019-10-03 10:45:52 +03:00
|
|
|
[Q.sql|
|
2020-12-08 17:22:31 +03:00
|
|
|
INSERT INTO hdb_catalog.hdb_metadata
|
|
|
|
(id, metadata) VALUES (1, $1::json)
|
|
|
|
ON CONFLICT (id) DO UPDATE SET metadata = $1::json
|
|
|
|
|] (Identity $ Q.AltJ metadata) True
|