2021-12-22 03:10:28 +03:00
|
|
|
{-# LANGUAGE StandaloneKindSignatures #-}
|
|
|
|
|
2022-05-02 08:03:12 +03:00
|
|
|
module Hasura.Backends.DataConnector.IR.Name
|
2021-12-22 03:10:28 +03:00
|
|
|
( Name (..),
|
|
|
|
NameType (..),
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey)
|
|
|
|
import Data.Kind (Type)
|
|
|
|
import Data.Text.Extended (ToTxt)
|
2022-05-02 08:03:12 +03:00
|
|
|
import Hasura.Backends.DataConnector.API qualified as API
|
2021-12-22 03:10:28 +03:00
|
|
|
import Hasura.Incremental (Cacheable)
|
|
|
|
import Hasura.Prelude
|
2022-04-28 04:51:58 +03:00
|
|
|
import Witch qualified
|
2021-12-22 03:10:28 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- | A tagged, opaque wrapper around 'Text' that provides a number of derived
|
|
|
|
-- derived instances (primarily as required by the @Backend@ typeclass).
|
|
|
|
--
|
|
|
|
-- This wrapper is indexed by 'NameType' so that different "names" can be
|
|
|
|
-- represented as semantically distinct types without the boilerplate of
|
|
|
|
-- actually defining these wrappers separately.
|
|
|
|
type Name :: NameType -> Type
|
|
|
|
newtype Name ty = Name {unName :: Text}
|
|
|
|
deriving stock (Data, Eq, Generic, Ord, Show)
|
|
|
|
deriving newtype
|
|
|
|
( Cacheable,
|
|
|
|
FromJSON,
|
|
|
|
FromJSONKey,
|
|
|
|
Hashable,
|
|
|
|
NFData,
|
|
|
|
ToJSON,
|
|
|
|
ToJSONKey,
|
|
|
|
ToTxt
|
|
|
|
)
|
|
|
|
|
2022-04-28 04:51:58 +03:00
|
|
|
instance Witch.From API.TableName (Name 'Table) where
|
2022-06-02 05:06:45 +03:00
|
|
|
from (API.TableName n) = Name n
|
2022-03-16 07:12:15 +03:00
|
|
|
|
2022-04-28 04:51:58 +03:00
|
|
|
instance Witch.From (Name 'Table) API.TableName where
|
2022-04-08 09:48:37 +03:00
|
|
|
from (Name n) = API.TableName n
|
|
|
|
|
2022-04-28 04:51:58 +03:00
|
|
|
instance Witch.From API.ColumnName (Name 'Column) where
|
2022-06-02 05:06:45 +03:00
|
|
|
from (API.ColumnName n) = Name n
|
2022-03-16 07:12:15 +03:00
|
|
|
|
2022-04-28 04:51:58 +03:00
|
|
|
instance Witch.From (Name 'Column) API.ColumnName where
|
2022-04-08 09:48:37 +03:00
|
|
|
from (Name n) = API.ColumnName n
|
|
|
|
|
2021-12-22 03:10:28 +03:00
|
|
|
-- | The "type" of "name" that the 'Name' type is meant to provide a textual
|
|
|
|
-- representation for.
|
|
|
|
--
|
|
|
|
-- In other words: an enumeration of all the types for which 'Name' acts as a
|
|
|
|
-- shared abstraction.
|
|
|
|
data NameType
|
|
|
|
= Column
|
|
|
|
| Function
|
|
|
|
| Table
|