2022-03-16 07:12:15 +03:00
{- # LANGUAGE DeriveAnyClass # -}
--
2022-05-02 08:03:12 +03:00
module Hasura.Backends.DataConnector.API.V0.Table
2022-03-16 07:12:15 +03:00
( TableInfo ( .. ) ,
TableName ( .. ) ,
)
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-08-04 11:34:45 +03:00
import Data.Aeson ( FromJSON , ToJSON )
2022-04-01 04:20:23 +03:00
import Data.Data ( Data )
import Data.Hashable ( Hashable )
2022-08-04 11:34:45 +03:00
import Data.List.NonEmpty ( NonEmpty )
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.Column qualified as API . V0
2022-04-01 04:20:23 +03:00
import Prelude
2022-03-16 07:12:15 +03:00
--------------------------------------------------------------------------------
2022-08-04 11:34:45 +03:00
newtype TableName = TableName { unTableName :: NonEmpty 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 ( FromJSON , ToJSON , ToSchema ) via Autodocodec TableName
instance HasCodec TableName where
2022-08-04 11:34:45 +03:00
codec =
named " TableName " $
dimapCodec TableName unTableName codec
<?> " The fully qualified name of a table, where the last item in the array is the table name and any earlier items represent the namespacing of the table name "
2022-03-16 07:12:15 +03:00
--------------------------------------------------------------------------------
-- | Table schema data from the 'SchemaResponse'.
data TableInfo = TableInfo
{ dtiName :: TableName ,
dtiColumns :: [ API . V0 . ColumnInfo ] ,
2022-07-01 15:20:07 +03:00
dtiPrimaryKey :: Maybe [ API . V0 . ColumnName ] ,
2022-03-16 07:12:15 +03:00
dtiDescription :: 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 TableInfo
instance HasCodec TableInfo where
codec =
object " TableInfo " $
TableInfo
2022-04-10 07:47:15 +03:00
<$> requiredField " name " " The name of the table " .= dtiName
2022-03-31 07:45:03 +03:00
<*> requiredField " columns " " The columns of the table " .= dtiColumns
<*> optionalFieldOrNull " primary_key " " The primary key of the table " .= dtiPrimaryKey
<*> optionalFieldOrNull " description " " Description of the table " .= dtiDescription