@@ -13,13 +13,17 @@ Squeal data definition language.
13 , DeriveDataTypeable
13 , DeriveDataTypeable
14 , DeriveGeneric
14 , DeriveGeneric
15 , FlexibleContexts
15 , FlexibleContexts
17 , GeneralizedNewtypeDeriving
18 , GeneralizedNewtypeDeriving
18 , KindSignatures
19 , KindSignatures
19 , LambdaCase
20 , LambdaCase
21+ , MultiParamTypeClasses
20 , OverloadedStrings
22 , OverloadedStrings
21 , RankNTypes
23 , RankNTypes
24+ , ScopedTypeVariables
22 , StandaloneDeriving
25 , StandaloneDeriving
23 , TypeInType
27 , TypeInType
24 , TypeOperators
28 , TypeOperators
@@ -31,6 +35,7 @@ module Squeal.PostgreSQL.Definition
31 -- * Create
35 -- * Create
32 , createTable
36 , createTable
33 , TableConstraintExpression (..)
37 , TableConstraintExpression (..)
36 , primaryKey
41 , primaryKey
@@ -158,13 +163,14 @@ newtype TableConstraintExpression
158data Column
163data Column
159 (columns :: ColumnsType)
164 (columns :: ColumnsType)
160 (column :: (Symbol,ColumnType))
165 (column :: (Symbol,ColumnType))
163− :: Has column columns ty
168+ :: Has column columns ty
164− => Column columns (column ::: ty)
170+ -> Column columns (column ::: ty)
165−deriving instance Show (Column columns columnty)
171+
166−deriving instance Eq (Column columns columnty)
172+renderColumn :: Column columns column -> ByteString
167−deriving instance Ord (Column columns columnty)
173+renderColumn (Column column) = renderAlias column
169-- | A `check` constraint is the most generic `TableConstraint` type.
175-- | A `check` constraint is the most generic `TableConstraint` type.
170-- It allows you to specify that the value in a certain column must satisfy
176-- It allows you to specify that the value in a certain column must satisfy
@@ -267,7 +273,7 @@ primaryKey columns = UnsafeTableConstraintExpression $
267-- "CREATE TABLE users (id serial, username text NOT NULL, CONSTRAINT pk_id PRIMARY KEY (id)); CREATE TABLE emails (id serial, userid integer NOT NULL, email text NOT NULL, CONSTRAINT pk_id PRIMARY KEY (id), CONSTRAINT fk_user_id FOREIGN KEY (userid) REFERENCES users (id) ON DELETE CASCADE ON UPDATE RESTRICT);"
273-- "CREATE TABLE users (id serial, username text NOT NULL, CONSTRAINT pk_id PRIMARY KEY (id)); CREATE TABLE emails (id serial, userid integer NOT NULL, email text NOT NULL, CONSTRAINT pk_id PRIMARY KEY (id), CONSTRAINT fk_user_id FOREIGN KEY (userid) REFERENCES users (id) ON DELETE CASCADE ON UPDATE RESTRICT);"
268foreignKey
274foreignKey
269 :: ( Has table schema reftable
275 :: ( Has table schema reftable
270− , reftable ~ (constraints :=> refsubcolumns)
276+ , refcolumns ~ UnconstrainTable reftable
271 , SameTypes subcolumns refsubcolumns
277 , SameTypes subcolumns refsubcolumns
272 , AllNotNull subcolumns
278 , AllNotNull subcolumns
273 , SOP.SListI subcolumns
279 , SOP.SListI subcolumns
@@ -388,7 +394,7 @@ alterTableRename table0 table1 = UnsafeDefinition $
388addConstraint
394addConstraint
389 :: KnownSymbol constraintName
395 :: KnownSymbol constraintName
390 => Alias constraintName
396 => Alias constraintName
391− -> TableConstraintExpression schema table constraint
397+ -> TableConstraintExpression schema (UnconstrainTable table) constraint
392 -> AlterTable schema table (AddConstraint constraintName constraint table)
398 -> AlterTable schema table (AddConstraint constraintName constraint table)
393addConstraint constraintName constraint = UnsafeAlterTable $
399addConstraint constraintName constraint = UnsafeAlterTable $
394 "ADD" <+> "CONSTRAINT" <+> renderAlias constraintName
400 "ADD" <+> "CONSTRAINT" <+> renderAlias constraintName