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