@@ -36,6 +36,7 @@ module Squeal.PostgreSQL.Schema
36 , NullityType (..)
36 , NullityType (..)
37 , ColumnType
37 , ColumnType
38 , ColumnsType
38 , ColumnsType
39 , TablesType
40 , TablesType
40 , Grouping (..)
41 , Grouping (..)
41 -- * Constraints
42 -- * Constraints
@@ -73,6 +74,7 @@ module Squeal.PostgreSQL.Schema
73 , ColumnConstraint (..)
74 , ColumnConstraint (..)
74 , DropDefault
75 , DropDefault
75 , DropDefaultList
76 , DropDefaultList
77+ , TableConstraint' (..)
78import Control.DeepSeq
80import Control.DeepSeq
@@ -129,11 +131,13 @@ type ColumnType = ([ColumnConstraint],NullityType)
129-- | `ColumnsType` is a kind synonym for a row of `ColumnType`s.
131-- | `ColumnsType` is a kind synonym for a row of `ColumnType`s.
130type ColumnsType = [(Symbol,ColumnType)]
132type ColumnsType = [(Symbol,ColumnType)]
134+type TableType = ([TableConstraint'],ColumnsType)
132-- | `TablesType` is a kind synonym for a row of `ColumnsType`s.
136-- | `TablesType` is a kind synonym for a row of `ColumnsType`s.
133-- It is used as a kind for both a schema, a disjoint union of tables,
137-- It is used as a kind for both a schema, a disjoint union of tables,
134-- and a joined table `Squeal.PostgreSQL.Query.FromClause`,
138-- and a joined table `Squeal.PostgreSQL.Query.FromClause`,
135-- a product of tables.
139-- a product of tables.
136−type TablesType = [(Symbol,ColumnsType)]
140+type TablesType = [(Symbol,TableType)]
138-- | `Grouping` is an auxiliary namespace, created by
142-- | `Grouping` is an auxiliary namespace, created by
139-- @GROUP BY@ clauses (`Squeal.PostgreSQL.Query.group`), and used
143-- @GROUP BY@ clauses (`Squeal.PostgreSQL.Query.group`), and used
@@ -261,13 +265,16 @@ type family NullifyColumns (columns :: ColumnsType) :: ColumnsType where
261 NullifyColumns ((column ::: ty) ': columns) =
265 NullifyColumns ((column ::: ty) ': columns) =
262 (column ::: NullifyType ty) ': NullifyColumns columns
266 (column ::: NullifyType ty) ': NullifyColumns columns
268+type family NullifyTable (table :: TableType) :: TableType where
269+ NullifyTable '( '[], columns) = '( '[], NullifyColumns columns)
264-- | `NullifyTables` is an idempotent that nullifies a `TablesType`
271-- | `NullifyTables` is an idempotent that nullifies a `TablesType`
265-- used to nullify the left or right hand side of an outer join
272-- used to nullify the left or right hand side of an outer join
266-- in a `Squeal.PostgreSQL.Query.FromClause`.
273-- in a `Squeal.PostgreSQL.Query.FromClause`.
267type family NullifyTables (tables :: TablesType) :: TablesType where
274type family NullifyTables (tables :: TablesType) :: TablesType where
268 NullifyTables '[] = '[]
275 NullifyTables '[] = '[]
269− NullifyTables ((table ::: columns) ': tables) =
276+ NullifyTables ((tab ::: table) ': tables) =
270− (table ::: NullifyColumns columns) ': NullifyTables tables
277+ (tab ::: NullifyTable table) ': NullifyTables tables
272-- | `Join` is simply promoted `++` and is used in @JOIN@s in
279-- | `Join` is simply promoted `++` and is used in @JOIN@s in
273-- `Squeal.PostgreSQL.Query.FromClause`s.
280-- `Squeal.PostgreSQL.Query.FromClause`s.
@@ -339,3 +346,8 @@ type family DropDefaultList constraints where
339 DropDefaultList ( 'Default ': constraints) = constraints
346 DropDefaultList ( 'Default ': constraints) = constraints
340 DropDefaultList (constraint ': constraints) =
347 DropDefaultList (constraint ': constraints) =
341 constraint ': DropDefaultList constraints
348 constraint ': DropDefaultList constraints
350+data TableConstraint'
353+ | ForeignKey [Symbol] Symbol [Symbol]