@@ -58,6 +58,8 @@ module Squeal.PostgreSQL.Schema
5858 , RelationsToTables
5959 , ColumnConstraint (..)
6060 , TableConstraint (..)
61+ , TableConstraints
62+ , NilTableConstraints
6163 , ConstraintInvolves
6264 , DropIfConstraintsInvolve
6365 -- * Aliases
@@ -201,30 +203,21 @@ data ColumnConstraint
201203-- | `ColumnType` encodes the allowance of @DEFAULT@ and @NULL@ and the
202204-- base `PGType` for a column.
203205--
204−-- >>> :kind 'NoDef :=> 'NotNull 'PGint4
205−-- 'NoDef :=> 'NotNull 'PGint4 :: (ColumnConstraint, NullityType)
206−-- >>> :kind 'NoDef :=> 'NotNull 'PGtext
207−-- 'NoDef :=> 'NotNull 'PGtext :: (ColumnConstraint, NullityType)
208−-- >>> import Data.Type.Equality
209−-- >>> Refl :: ColumnType :~: (ColumnConstraint, NullityType)
210−-- Refl
206+-- >>> :set -XTypeFamilies -XTypeInType
207+-- >>> import GHC.TypeLits
208+-- >>> type family IdColumn :: ColumnType where IdColumn = 'Def :=> 'NotNull 'PGint4
209+-- >>> type family EmailColumn :: ColumnType where EmailColumn = 'NoDef :=> 'Null 'PGtext
211210type ColumnType = (ColumnConstraint,NullityType)
212211
213212-- | `ColumnsType` is a row of `ColumnType`s.
214213--
215−-- >>> import GHC.TypeLits
216214-- >>> :{
217−-- type Columns =
218−-- '[ "name" ::: 'NoDef :=> 'NotNull 'PGtext
219−-- , "id" ::: 'Def :=> 'NotNull 'PGint4
220−-- ]
215+-- type family UsersColumns :: ColumnsType where
216+-- UsersColumns =
217+-- '[ "name" ::: 'NoDef :=> 'NotNull 'PGtext
218+-- , "id" ::: 'Def :=> 'NotNull 'PGint4
219+-- ]
221220-- :}
222−--
223−-- >>> :kind Columns
224−-- Columns :: [(Symbol, (ColumnConstraint, NullityType))]
225−-- >>> import Data.Type.Equality
226−-- >>> Refl :: ColumnsType :~: [(Symbol, (ColumnConstraint, NullityType))]
227−-- Refl
228221type ColumnsType = [(Symbol,ColumnType)]
229222
230223-- | `TableConstraint` encodes various forms of data constraints
@@ -235,25 +228,27 @@ data TableConstraint
235228 | PrimaryKey [Symbol]
236229 | ForeignKey [Symbol] Symbol [Symbol]
237230
231+-- | A `TableConstraints` is a set of aliased `TableConstraint`s.
232+type TableConstraints = [(Symbol,TableConstraint)]
233+-- | A monokinded empty `TableConstraints`.
234+type family NilTableConstraints :: TableConstraints where
235+ NilTableConstraints = '[]
236+
238237-- | `TableType` encodes a row of constraints on a table as well as the types
239238-- of its columns.
240239--
241240-- >>> :{
242−-- type UsersTable =
243−-- '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
244−-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
245−-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
246−-- ]
241+-- type family UsersTable :: TableType where
242+-- UsersTable =
243+-- '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
244+-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
245+-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
246+-- ]
247247-- :}
248−--
249−-- >>> :kind UsersTable
250−-- UsersTable :: ([(Symbol, TableConstraint)],
251−-- [(Symbol, (ColumnConstraint, NullityType))])
252−type TableType = ([(Symbol,TableConstraint)],ColumnsType)
248+type TableType = (TableConstraints,ColumnsType)
253249
254250-- | `TablesType` is a row of `TableType`s, thought of as a union.
255251--
256−-- >>> :set -XTypeFamilies -XTypeInType
257252-- >>> :{
258253-- type family Schema :: TablesType where
259254-- Schema =
@@ -273,25 +268,22 @@ type TableType = ([(Symbol,TableConstraint)],ColumnsType)
273268-- ]
274269-- ]
275270-- :}
276−--
277271type TablesType = [(Symbol,TableType)]
278−-- | A monokinded `'[]` of `TablesType`.
272+-- | A monokinded empty `TablesType`.
279273type family NilTables :: TablesType where NilTables = '[]
280274
281275-- | `RelationType` is a row of `NullityType`
282276--
283277-- >>> :{
284−-- type Relation =
285−-- '[ "name" ::: 'NotNull 'PGtext
286−-- , "age" ::: 'NotNull 'PGint4
287−-- , "dateOfBirth" ::: 'Null 'PGdate
288−-- ]
278+-- type family PersonRelation :: RelationType where
279+-- PersonRelation =
280+-- '[ "name" ::: 'NotNull 'PGtext
281+-- , "age" ::: 'NotNull 'PGint4
282+-- , "dateOfBirth" ::: 'Null 'PGdate
283+-- ]
289284-- :}
290−--
291−-- >>> :kind Relation
292−-- Relation :: [(Symbol, NullityType)]
293285type RelationType = [(Symbol,NullityType)]
294−-- | A monokinded `'[]` of `RelationType`.
286+-- | A monokinded empty `RelationType`.
295287type family NilRelation :: RelationType where NilRelation = '[]
296288
297289-- | `RelationsType` is a row of `RelationType`s, thought of as a product.