2022-03-16 07:12:15 +03:00
|
|
|
{-# LANGUAGE DeriveAnyClass #-}
|
|
|
|
|
|
|
|
--
|
2022-05-02 08:03:12 +03:00
|
|
|
module Hasura.Backends.DataConnector.API.V0.Column
|
2022-03-16 07:12:15 +03:00
|
|
|
( ColumnInfo (..),
|
|
|
|
ColumnName (..),
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-03-31 07:45:03 +03:00
|
|
|
import Autodocodec
|
|
|
|
import Autodocodec.OpenAPI ()
|
2022-04-01 04:20:23 +03:00
|
|
|
import Control.DeepSeq (NFData)
|
2022-03-31 07:45:03 +03:00
|
|
|
import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey)
|
2022-04-01 04:20:23 +03:00
|
|
|
import Data.Data (Data)
|
|
|
|
import Data.Hashable (Hashable)
|
2022-03-31 07:45:03 +03:00
|
|
|
import Data.OpenApi (ToSchema)
|
2022-04-01 04:20:23 +03:00
|
|
|
import Data.Text (Text)
|
|
|
|
import GHC.Generics (Generic)
|
2022-05-02 08:03:12 +03:00
|
|
|
import Hasura.Backends.DataConnector.API.V0.Scalar.Type qualified as API.V0.Scalar
|
2022-04-01 04:20:23 +03:00
|
|
|
import Prelude
|
2022-03-16 07:12:15 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-03-31 07:45:03 +03:00
|
|
|
newtype ColumnName = ColumnName {unColumnName :: Text}
|
2022-03-16 07:12:15 +03:00
|
|
|
deriving stock (Eq, Ord, Show, Generic, Data)
|
2022-04-01 04:20:23 +03:00
|
|
|
deriving anyclass (NFData, Hashable)
|
2022-03-31 07:45:03 +03:00
|
|
|
deriving newtype (ToJSONKey, FromJSONKey)
|
|
|
|
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec ColumnName
|
|
|
|
|
|
|
|
instance HasCodec ColumnName where
|
|
|
|
codec = dimapCodec ColumnName unColumnName textCodec
|
2022-03-16 07:12:15 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
data ColumnInfo = ColumnInfo
|
|
|
|
{ dciName :: ColumnName,
|
|
|
|
dciType :: API.V0.Scalar.Type,
|
|
|
|
dciNullable :: Bool,
|
|
|
|
dciDescription :: Maybe Text
|
|
|
|
}
|
|
|
|
deriving stock (Eq, Ord, Show, Generic, Data)
|
2022-04-01 04:20:23 +03:00
|
|
|
deriving anyclass (NFData, Hashable)
|
2022-03-31 07:45:03 +03:00
|
|
|
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec ColumnInfo
|
|
|
|
|
|
|
|
instance HasCodec ColumnInfo where
|
|
|
|
codec =
|
|
|
|
object "ColumnInfo" $
|
|
|
|
ColumnInfo
|
|
|
|
<$> requiredField "name" "Column name" .= dciName
|
|
|
|
<*> requiredField "type" "Column type" .= dciType
|
|
|
|
<*> requiredField "nullable" "Is column nullable" .= dciNullable
|
|
|
|
<*> optionalFieldOrNull "description" "Column description" .= dciDescription
|