2021-03-15 16:02:58 +03:00
|
|
|
module Hasura.SQL.Backend
|
2021-04-22 00:44:37 +03:00
|
|
|
( PostgresKind(..)
|
|
|
|
, BackendType(..)
|
2021-03-15 16:02:58 +03:00
|
|
|
, supportedBackends
|
|
|
|
) where
|
2020-10-22 23:42:27 +03:00
|
|
|
|
2021-02-03 19:17:20 +03:00
|
|
|
import Hasura.Prelude
|
|
|
|
|
2021-03-18 23:34:11 +03:00
|
|
|
import Data.Aeson
|
2021-04-22 00:44:37 +03:00
|
|
|
import Data.Proxy
|
2021-03-18 23:34:11 +03:00
|
|
|
import Data.Text (unpack)
|
|
|
|
import Data.Text.Extended
|
2021-02-03 19:17:20 +03:00
|
|
|
|
2021-04-22 00:44:37 +03:00
|
|
|
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
|
|
|
|
deriving (Eq, Ord)
|
2021-02-14 09:07:52 +03:00
|
|
|
|
|
|
|
-- | An enum that represents each backend we support.
|
2021-04-22 00:44:37 +03:00
|
|
|
-- As we lift values to the type level, we expect this type to have an Enum instance.
|
2021-03-18 23:34:11 +03:00
|
|
|
data BackendType
|
2021-04-22 00:44:37 +03:00
|
|
|
= Postgres PostgresKind
|
2021-03-18 23:34:11 +03:00
|
|
|
| MSSQL
|
2021-04-12 13:18:29 +03:00
|
|
|
| BigQuery
|
2021-04-22 00:44:37 +03:00
|
|
|
deriving (Eq, Ord)
|
|
|
|
|
2021-03-18 23:34:11 +03:00
|
|
|
|
|
|
|
-- | The name of the backend, as we expect it to appear in our metadata and API.
|
|
|
|
instance ToTxt BackendType where
|
2021-04-22 00:44:37 +03:00
|
|
|
toTxt (Postgres Vanilla) = "postgres"
|
|
|
|
toTxt MSSQL = "mssql"
|
|
|
|
toTxt BigQuery = "bigquery"
|
2021-03-18 23:34:11 +03:00
|
|
|
|
|
|
|
-- | 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
|
|
|
|
|
2021-04-22 00:44:37 +03:00
|
|
|
instance Cacheable (Proxy (b :: BackendType))
|
|
|
|
|
2021-03-18 23:34:11 +03:00
|
|
|
|
|
|
|
supportedBackends :: [BackendType]
|
2021-04-22 00:44:37 +03:00
|
|
|
supportedBackends =
|
|
|
|
[ Postgres Vanilla
|
|
|
|
, MSSQL
|
|
|
|
, BigQuery
|
|
|
|
]
|