@@ -36,6 +36,7 @@ module Squeal.PostgreSQL.Schema
3636 , NullityType (..)
3737 , ColumnType
3838 , ColumnsType
39+ , TableType
3940 , TablesType
4041 , Grouping (..)
4142 -- * Constraints
@@ -73,6 +74,7 @@ module Squeal.PostgreSQL.Schema
7374 , ColumnConstraint (..)
7475 , DropDefault
7576 , DropDefaultList
77+ , TableConstraint' (..)
7678 ) where
7779
7880import Control.DeepSeq
@@ -129,11 +131,13 @@ type ColumnType = ([ColumnConstraint],NullityType)
129131-- | `ColumnsType` is a kind synonym for a row of `ColumnType`s.
130132type ColumnsType = [(Symbol,ColumnType)]
131133
134+type TableType = ([TableConstraint'],ColumnsType)
135+
132136-- | `TablesType` is a kind synonym for a row of `ColumnsType`s.
133137-- It is used as a kind for both a schema, a disjoint union of tables,
134138-- and a joined table `Squeal.PostgreSQL.Query.FromClause`,
135139-- a product of tables.
136−type TablesType = [(Symbol,ColumnsType)]
140+type TablesType = [(Symbol,TableType)]
137141
138142-- | `Grouping` is an auxiliary namespace, created by
139143-- @GROUP BY@ clauses (`Squeal.PostgreSQL.Query.group`), and used
@@ -261,13 +265,16 @@ type family NullifyColumns (columns :: ColumnsType) :: ColumnsType where
261265 NullifyColumns ((column ::: ty) ': columns) =
262266 (column ::: NullifyType ty) ': NullifyColumns columns
263267
268+type family NullifyTable (table :: TableType) :: TableType where
269+ NullifyTable '( '[], columns) = '( '[], NullifyColumns columns)
270+
264271-- | `NullifyTables` is an idempotent that nullifies a `TablesType`
265272-- used to nullify the left or right hand side of an outer join
266273-- in a `Squeal.PostgreSQL.Query.FromClause`.
267274type family NullifyTables (tables :: TablesType) :: TablesType where
268275 NullifyTables '[] = '[]
269− NullifyTables ((table ::: columns) ': tables) =
270− (table ::: NullifyColumns columns) ': NullifyTables tables
276+ NullifyTables ((tab ::: table) ': tables) =
277+ (tab ::: NullifyTable table) ': NullifyTables tables
271278
272279-- | `Join` is simply promoted `++` and is used in @JOIN@s in
273280-- `Squeal.PostgreSQL.Query.FromClause`s.
@@ -339,3 +346,8 @@ type family DropDefaultList constraints where
339346 DropDefaultList ( 'Default ': constraints) = constraints
340347 DropDefaultList (constraint ': constraints) =
341348 constraint ': DropDefaultList constraints
349+
350+data TableConstraint'
351+ = Check [Symbol]
352+ | Uniques [Symbol]
353+ | ForeignKey [Symbol] Symbol [Symbol]