graphql-engine/server/src-lib/Hasura/SQL/Backend.hs
Chris Done f7a202a363 BigQuery Feature Branch
This will implement BigQuery support.

Co-authored-by: Antoine Leblanc <1618949+nicuveo@users.noreply.github.com>
Co-authored-by: Sibi Prabakaran <737477+psibi@users.noreply.github.com>
Co-authored-by: Aniket Deshpande <922486+aniketd@users.noreply.github.com>
Co-authored-by: Vamshi Surabhi <6562944+0x777@users.noreply.github.com>
GitOrigin-RevId: 1a6ffaf34233e13e8125a5c908eaa7e32d65007b
2021-04-12 10:19:20 +00:00

41 lines
1.2 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
| BigQuery
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"
toTxt BigQuery = "bigquery"
-- | 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]