mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 04:24:35 +03:00
9ef603360c
Co-authored-by: Vamshi Surabhi <vamshi@hasura.io> Co-authored-by: Vladimir Ciobanu <admin@cvlad.info> Co-authored-by: Antoine Leblanc <antoine@hasura.io> Co-authored-by: Stylish Haskell Bot <stylish-haskell@users.noreply.github.com> GitOrigin-RevId: 9d631878037637f3ed2994b5d0525efd978f7b8f
39 lines
1.1 KiB
Haskell
39 lines
1.1 KiB
Haskell
module Hasura.SQL.Backend where
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Data.GADT.Compare
|
|
import Type.Reflection
|
|
import Unsafe.Coerce
|
|
|
|
|
|
-- | An enum that represents each backend we support.
|
|
data BackendType = Postgres
|
|
deriving (Show, Eq, Ord, Bounded, Enum)
|
|
|
|
|
|
-- | A singleton-like GADT that associates a tag to each backend.
|
|
-- It must contain one tag per backend in @BackendType@.
|
|
data BackendTag (b :: BackendType) where
|
|
PostgresTag :: BackendTag 'Postgres
|
|
|
|
|
|
-- | How to convert back from a tag to a runtime value.
|
|
reify :: BackendTag b -> BackendType
|
|
reify PostgresTag = Postgres
|
|
|
|
|
|
-- We need those instances to be able to use a @BackendTag@ as a key in a
|
|
-- dependent map. Using @BackendType@ as a data kind, makes it difficult to use
|
|
-- @Typeable@, hence the reliance on `unsafeCoerce`.
|
|
instance GEq BackendTag where
|
|
geq b1 b2
|
|
| reify b1 == reify b2 = unsafeCoerce $ Just Refl
|
|
| otherwise = Nothing
|
|
|
|
instance GCompare BackendTag where
|
|
gcompare b1 b2 = case compare (reify b1) (reify b2) of
|
|
EQ -> unsafeCoerce GEQ
|
|
LT -> GLT
|
|
GT -> GGT
|