{-# language DeriveFunctor #-}
{-# language DerivingStrategies #-}
{-# language DuplicateRecordFields #-}
{-# language NamedFieldPuns #-}
{-# language StandaloneKindSignatures #-}
{-# language StrictData #-}

module Rel8.Schema.Table
  ( TableSchema(..)
  , ppTable
  )
where

-- base
import Data.Kind ( Type )
import Prelude

-- pretty
import Text.PrettyPrint ( Doc )

-- rel8
import Rel8.Schema.QualifiedName (QualifiedName, ppQualifiedName)


-- | The schema for a table. This is used to specify the name and schema that a
-- table belongs to (the @FROM@ part of a SQL query), along with the schema of
-- the columns within this table.
-- 
-- For each selectable table in your database, you should provide a
-- @TableSchema@ in order to interact with the table via Rel8.
type TableSchema :: Type -> Type
data TableSchema names = TableSchema
  { forall names. TableSchema names -> QualifiedName
name :: QualifiedName
    -- ^ The name of the table.
  , forall names. TableSchema names -> names
columns :: names
    -- ^ The columns of the table. Typically you would use a 'Rel8.Rel8able'
    -- data type here, parameterized by the 'Rel8.Name' context.
  }
  deriving stock (forall a b. (a -> b) -> TableSchema a -> TableSchema b)
-> (forall a b. a -> TableSchema b -> TableSchema a)
-> Functor TableSchema
forall a b. a -> TableSchema b -> TableSchema a
forall a b. (a -> b) -> TableSchema a -> TableSchema b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> TableSchema a -> TableSchema b
fmap :: forall a b. (a -> b) -> TableSchema a -> TableSchema b
$c<$ :: forall a b. a -> TableSchema b -> TableSchema a
<$ :: forall a b. a -> TableSchema b -> TableSchema a
Functor


ppTable :: TableSchema a -> Doc
ppTable :: forall a. TableSchema a -> Doc
ppTable TableSchema {QualifiedName
$sel:name:TableSchema :: forall names. TableSchema names -> QualifiedName
name :: QualifiedName
name} = QualifiedName -> Doc
ppQualifiedName QualifiedName
name