@@ -58,6 +58,8 @@ module Squeal.PostgreSQL.Schema
58 , RelationsToTables
58 , RelationsToTables
59 , ColumnConstraint (..)
59 , ColumnConstraint (..)
60 , TableConstraint (..)
60 , TableConstraint (..)
62+ , NilTableConstraints
61 , ConstraintInvolves
63 , ConstraintInvolves
62 , DropIfConstraintsInvolve
64 , DropIfConstraintsInvolve
63 -- * Aliases
65 -- * Aliases
@@ -201,30 +203,21 @@ data ColumnConstraint
201-- | `ColumnType` encodes the allowance of @DEFAULT@ and @NULL@ and the
203-- | `ColumnType` encodes the allowance of @DEFAULT@ and @NULL@ and the
202-- base `PGType` for a column.
204-- base `PGType` for a column.
204−-- >>> :kind 'NoDef :=> 'NotNull 'PGint4
206+-- >>> :set -XTypeFamilies -XTypeInType
205−-- 'NoDef :=> 'NotNull 'PGint4 :: (ColumnConstraint, NullityType)
207+-- >>> import GHC.TypeLits
206−-- >>> :kind 'NoDef :=> 'NotNull 'PGtext
208+-- >>> type family IdColumn :: ColumnType where IdColumn = 'Def :=> 'NotNull 'PGint4
207−-- 'NoDef :=> 'NotNull 'PGtext :: (ColumnConstraint, NullityType)
209+-- >>> type family EmailColumn :: ColumnType where EmailColumn = 'NoDef :=> 'Null 'PGtext
208−-- >>> import Data.Type.Equality
209−-- >>> Refl :: ColumnType :~: (ColumnConstraint, NullityType)
211type ColumnType = (ColumnConstraint,NullityType)
210type ColumnType = (ColumnConstraint,NullityType)
213-- | `ColumnsType` is a row of `ColumnType`s.
212-- | `ColumnsType` is a row of `ColumnType`s.
215−-- >>> import GHC.TypeLits
217−-- type Columns =
215+-- type family UsersColumns :: ColumnsType where
218−-- '[ "name" ::: 'NoDef :=> 'NotNull 'PGtext
217+-- '[ "name" ::: 'NoDef :=> 'NotNull 'PGtext
219−-- , "id" ::: 'Def :=> 'NotNull 'PGint4
218+-- , "id" ::: 'Def :=> 'NotNull 'PGint4
224−-- Columns :: [(Symbol, (ColumnConstraint, NullityType))]
225−-- >>> import Data.Type.Equality
226−-- >>> Refl :: ColumnsType :~: [(Symbol, (ColumnConstraint, NullityType))]
228type ColumnsType = [(Symbol,ColumnType)]
221type ColumnsType = [(Symbol,ColumnType)]
230-- | `TableConstraint` encodes various forms of data constraints
223-- | `TableConstraint` encodes various forms of data constraints
@@ -235,25 +228,27 @@ data TableConstraint
235 | PrimaryKey [Symbol]
228 | PrimaryKey [Symbol]
236 | ForeignKey [Symbol] Symbol [Symbol]
229 | ForeignKey [Symbol] Symbol [Symbol]
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 = '[]
238-- | `TableType` encodes a row of constraints on a table as well as the types
237-- | `TableType` encodes a row of constraints on a table as well as the types
239-- of its columns.
238-- of its columns.
241+-- type family UsersTable :: TableType where
242−-- type UsersTable =
242+-- UsersTable =
243−-- '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
243+-- '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
244−-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
244+-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
245−-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
245+-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
249−-- >>> :kind UsersTable
250−-- UsersTable :: ([(Symbol, TableConstraint)],
251−-- [(Symbol, (ColumnConstraint, NullityType))])
252−type TableType = ([(Symbol,TableConstraint)],ColumnsType)
248+type TableType = (TableConstraints,ColumnsType)
254-- | `TablesType` is a row of `TableType`s, thought of as a union.
250-- | `TablesType` is a row of `TableType`s, thought of as a union.
256−-- >>> :set -XTypeFamilies -XTypeInType
258-- type family Schema :: TablesType where
253-- type family Schema :: TablesType where
259-- Schema =
254-- Schema =
@@ -273,25 +268,22 @@ type TableType = ([(Symbol,TableConstraint)],ColumnsType)
277type TablesType = [(Symbol,TableType)]
271type TablesType = [(Symbol,TableType)]
278−-- | A monokinded `'[]` of `TablesType`.
272+-- | A monokinded empty `TablesType`.
279type family NilTables :: TablesType where NilTables = '[]
273type family NilTables :: TablesType where NilTables = '[]
281-- | `RelationType` is a row of `NullityType`
275-- | `RelationType` is a row of `NullityType`
284−-- type Relation =
278+-- type family PersonRelation :: RelationType where
285−-- '[ "name" ::: 'NotNull 'PGtext
280+-- '[ "name" ::: 'NotNull 'PGtext
286−-- , "age" ::: 'NotNull 'PGint4
281+-- , "age" ::: 'NotNull 'PGint4
287−-- , "dateOfBirth" ::: 'Null 'PGdate
282+-- , "dateOfBirth" ::: 'Null 'PGdate
291−-- >>> :kind Relation
292−-- Relation :: [(Symbol, NullityType)]
293type RelationType = [(Symbol,NullityType)]
285type RelationType = [(Symbol,NullityType)]
294−-- | A monokinded `'[]` of `RelationType`.
286+-- | A monokinded empty `RelationType`.
295type family NilRelation :: RelationType where NilRelation = '[]
287type family NilRelation :: RelationType where NilRelation = '[]
297-- | `RelationsType` is a row of `RelationType`s, thought of as a product.
289-- | `RelationsType` is a row of `RelationType`s, thought of as a product.