graphql-engine/server/src-lib/Hasura/SQL/Backend.hs
Abby Sassel 1afa4ac3cc server/citus: feature branch
Co-authored-by: Vladimir Ciobanu <1017953+vladciobanu@users.noreply.github.com>
Co-authored-by: Antoine Leblanc <1618949+nicuveo@users.noreply.github.com>
Co-authored-by: Ikechukwu Eze <22247592+iykekings@users.noreply.github.com>
Co-authored-by: Philip Lykke Carlsen <358550+plcplc@users.noreply.github.com>
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: 1b964fe5f5f50380172cb702b6a328fed782b6b7
2021-05-21 02:47:51 +00:00

60 lines
1.6 KiB
Haskell

module Hasura.SQL.Backend
( PostgresKind(..)
, BackendType(..)
, supportedBackends
) where
import Hasura.Prelude
import Data.Aeson
import Data.Proxy
import Data.Text (unpack)
import Data.Text.Extended
import Hasura.Incremental
-- | Argument to Postgres; we represent backends which are variations on Postgres as sub-types of
-- Postgres. This value indicates which "flavour" of Postgres a backend is.
data PostgresKind
= Vanilla
| Citus
deriving (Eq, Ord)
-- | An enum that represents each backend we support.
-- As we lift values to the type level, we expect this type to have an Enum instance.
data BackendType
= Postgres PostgresKind
| MSSQL
| BigQuery
deriving (Eq, Ord)
-- | The name of the backend, as we expect it to appear in our metadata and API.
instance ToTxt BackendType where
toTxt (Postgres Vanilla) = "postgres"
toTxt (Postgres Citus) = "citus"
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
instance Cacheable (Proxy (b :: BackendType))
supportedBackends :: [BackendType]
supportedBackends =
[ Postgres Vanilla
, Postgres Citus
, MSSQL
, BigQuery
]