module Hasura.Backends.DataConnector.Schema.Table
  ( Table (..),
  )
where

--------------------------------------------------------------------------------

import Hasura.Backends.DataConnector.IR.Table qualified as Table (Name)
import Hasura.Backends.DataConnector.Schema.Column (Column)
import Hasura.Prelude

--------------------------------------------------------------------------------

-- | A schematic representation which captures a named collection of columns
--
-- TODO(cdparks): schematic in the sense of "relating to a schema" or symbolic?
-- This language is also used in the @Column@ documentation
--
-- An element of a table is known as a row, record, tuple, or object,
-- and conforms to the shape specified by the list of @Column@s below.
--
-- cf. https://en.wikipedia.org/wiki/Table_(database)
--     https://www.postgresql.org/docs/13/ddl-basics.html
--
-- NOTE(jkachmar): This type shouldn't _need_ ser/de instances, but they're
-- imposed by the 'Backend' class.
data Table = Table
  { Table -> Name
name :: Table.Name,
    Table -> [Column]
columns :: [Column],
    -- TODO(cdparks): Composite primary keys
    Table -> Maybe Text
primaryKey :: Maybe Text,
    Table -> Maybe Text
description :: Maybe Text
  }
  deriving stock (Typeable Table
DataType
Constr
Typeable Table
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Table -> c Table)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Table)
-> (Table -> Constr)
-> (Table -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Table))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Table))
-> ((forall b. Data b => b -> b) -> Table -> Table)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r)
-> (forall u. (forall d. Data d => d -> u) -> Table -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Table -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Table -> m Table)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Table -> m Table)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Table -> m Table)
-> Data Table
Table -> DataType
Table -> Constr
(forall b. Data b => b -> b) -> Table -> Table
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table -> c Table
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Table
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Table -> u
forall u. (forall d. Data d => d -> u) -> Table -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Table -> m Table
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Table -> m Table
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Table
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table -> c Table
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Table)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Table)
$cTable :: Constr
$tTable :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Table -> m Table
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Table -> m Table
gmapMp :: (forall d. Data d => d -> m d) -> Table -> m Table
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Table -> m Table
gmapM :: (forall d. Data d => d -> m d) -> Table -> m Table
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Table -> m Table
gmapQi :: Int -> (forall d. Data d => d -> u) -> Table -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Table -> u
gmapQ :: (forall d. Data d => d -> u) -> Table -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Table -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Table -> r
gmapT :: (forall b. Data b => b -> b) -> Table -> Table
$cgmapT :: (forall b. Data b => b -> b) -> Table -> Table
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Table)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Table)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Table)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Table)
dataTypeOf :: Table -> DataType
$cdataTypeOf :: Table -> DataType
toConstr :: Table -> Constr
$ctoConstr :: Table -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Table
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Table
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table -> c Table
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Table -> c Table
$cp1Data :: Typeable Table
Data, Table -> Table -> Bool
(Table -> Table -> Bool) -> (Table -> Table -> Bool) -> Eq Table
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Table -> Table -> Bool
$c/= :: Table -> Table -> Bool
== :: Table -> Table -> Bool
$c== :: Table -> Table -> Bool
Eq, (forall x. Table -> Rep Table x)
-> (forall x. Rep Table x -> Table) -> Generic Table
forall x. Rep Table x -> Table
forall x. Table -> Rep Table x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Table x -> Table
$cfrom :: forall x. Table -> Rep Table x
Generic, Eq Table
Eq Table
-> (Table -> Table -> Ordering)
-> (Table -> Table -> Bool)
-> (Table -> Table -> Bool)
-> (Table -> Table -> Bool)
-> (Table -> Table -> Bool)
-> (Table -> Table -> Table)
-> (Table -> Table -> Table)
-> Ord Table
Table -> Table -> Bool
Table -> Table -> Ordering
Table -> Table -> Table
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Table -> Table -> Table
$cmin :: Table -> Table -> Table
max :: Table -> Table -> Table
$cmax :: Table -> Table -> Table
>= :: Table -> Table -> Bool
$c>= :: Table -> Table -> Bool
> :: Table -> Table -> Bool
$c> :: Table -> Table -> Bool
<= :: Table -> Table -> Bool
$c<= :: Table -> Table -> Bool
< :: Table -> Table -> Bool
$c< :: Table -> Table -> Bool
compare :: Table -> Table -> Ordering
$ccompare :: Table -> Table -> Ordering
$cp1Ord :: Eq Table
Ord, Int -> Table -> ShowS
[Table] -> ShowS
Table -> String
(Int -> Table -> ShowS)
-> (Table -> String) -> ([Table] -> ShowS) -> Show Table
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Table] -> ShowS
$cshowList :: [Table] -> ShowS
show :: Table -> String
$cshow :: Table -> String
showsPrec :: Int -> Table -> ShowS
$cshowsPrec :: Int -> Table -> ShowS
Show)