mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 04:24:35 +03:00
a2cf9a53c2
GitOrigin-RevId: 3d1a7618a4ec086c2d255549a6c15087201e9ab0
34 lines
1.1 KiB
Haskell
34 lines
1.1 KiB
Haskell
-- | Functions for fetching and updating @'Metadata' in the catalog.
|
|
module Hasura.RQL.DDL.Schema.Catalog
|
|
( fetchMetadataFromCatalog
|
|
, setMetadataInCatalog
|
|
) where
|
|
|
|
import Hasura.Prelude
|
|
|
|
import qualified Database.PG.Query as Q
|
|
|
|
import Hasura.Backends.Postgres.Connection
|
|
import Hasura.RQL.Types.Error
|
|
import Hasura.RQL.Types.Metadata
|
|
|
|
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
|
|
[Q.sql|
|
|
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
|