graphql-engine/server/src-lib/Hasura/SQL/Backend.hs
Rakesh Emmadi 9ef603360c server: generalize schema cache building (#496)
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
2021-02-14 06:08:46 +00:00

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