mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 12:31:52 +03:00
405b29c82d
GitOrigin-RevId: 251b8dbeb5181e42cca0369abf54bfc2179ad3d8
39 lines
1.1 KiB
Haskell
39 lines
1.1 KiB
Haskell
module Hasura.SQL.Backend
|
|
( BackendType(..)
|
|
, supportedBackends
|
|
) where
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Data.Aeson
|
|
import Data.Text (unpack)
|
|
import Data.Text.Extended
|
|
|
|
|
|
-- | An enum that represents each backend we support.
|
|
-- This type MUST be an enumeration (an enumeration consists of one or
|
|
-- more nullary, non-GADT constructors).
|
|
data BackendType
|
|
= Postgres
|
|
| MSSQL
|
|
deriving (Eq, Ord, Bounded, Enum)
|
|
|
|
-- | The name of the backend, as we expect it to appear in our metadata and API.
|
|
instance ToTxt BackendType where
|
|
toTxt Postgres = "postgres"
|
|
toTxt MSSQL = "mssql"
|
|
|
|
-- | The FromJSON instance uses this lookup mechanism to avoid having
|
|
-- to duplicate and hardcode the backend string.
|
|
instance FromJSON BackendType where
|
|
parseJSON = withText "backend type" \name ->
|
|
lookup name [(toTxt b, b) | b <- supportedBackends]
|
|
`onNothing` fail ("got: " <> unpack name <> ", expected one of: " <> unpack (commaSeparated supportedBackends))
|
|
|
|
instance ToJSON BackendType where
|
|
toJSON = String . toTxt
|
|
|
|
|
|
supportedBackends :: [BackendType]
|
|
supportedBackends = [minBound @BackendType .. maxBound]
|