on da76712 help sign in
rel8/src/Rel8/Schema/Table.hs
49 lines 1.5 kB history raw
1{-# language DeriveFunctor #-}
2{-# language DerivingStrategies #-}
3{-# language DisambiguateRecordFields #-}
4{-# language NamedFieldPuns #-}
5{-# language StandaloneKindSignatures #-}
7module Rel8.Schema.Table
8 ( TableSchema(..)
9 , ppTable
10 )
11where
13-- base
14import Data.Kind ( Type )
15import Prelude
17-- opaleye
18import qualified Opaleye.Internal.HaskellDB.Sql as Opaleye
19import qualified Opaleye.Internal.HaskellDB.Sql.Print as Opaleye
21-- pretty
22import Text.PrettyPrint ( Doc )
25-- | The schema for a table. This is used to specify the name and schema that a
26-- table belongs to (the @FROM@ part of a SQL query), along with the schema of
27-- the columns within this table.
28--
29-- For each selectable table in your database, you should provide a
30-- @TableSchema@ in order to interact with the table via Rel8.
31type TableSchema :: Type -> Type
32data TableSchema names = TableSchema
33 { name :: String
34 -- ^ The name of the table.
35 , schema :: Maybe String
36 -- ^ The schema that this table belongs to. If 'Nothing', whatever is on
37 -- the connection's @search_path@ will be used.
38 , columns :: names
39 -- ^ The columns of the table. Typically you would use a a higher-kinded
40 -- data type here, parameterized by the 'Rel8.ColumnSchema.ColumnSchema' functor.
41 }
42 deriving stock Functor
45ppTable :: TableSchema a -> Doc
46ppTable TableSchema {name, schema} = Opaleye.ppTable Opaleye.SqlTable
47 { sqlTableSchemaName = schema
48 , sqlTableName = name
49 }