on dev help sign in
rejigger constraints a bit
commit687faef5d57c8c767c81a941b35147fbc712aa82 authorEitan Chatav <eitan.chatav@gmail.com> dateSat 23 Dec 2017, 18:50 (9 years ago) parent41b3514
7 files changed+106−103
squeal-postgresql/exe/Example.hs+13−12 squeal-postgresql/squeal-postgresql.cabal+1 squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+32−22 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+28−28 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+5−7 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+25−34 stack.yaml+2
squeal-postgresql/exe/Example.hs+13−12
@@ -24,15 +24,16 @@ import qualified Generics.SOP as SOP
2424import qualified GHC.Generics as GHC
2525
2626type Schema =
27− '[ "users" ::: '[] :=>
28− '[ "id" ::: AsSet '[ 'Default, 'Unique] :=> 'NotNull 'PGint4
29− , "name" ::: '[] :=> 'NotNull 'PGtext
27+ '[ "users" :::
28+ '[] :=>
29+ '[ "id" ::: 'Def :=> 'NotNull 'PGint4
30+ , "name" ::: 'NoDef :=> 'NotNull 'PGtext
3031 ]
31− , "emails" ::: AsSet
32− '[ 'ForeignKey '["user_id"] "users" '["id"] ] :=>
33− '[ "id" ::: AsSet '[ 'Default, 'Unique] :=> 'NotNull 'PGint4
34− , "user_id" ::: '[] :=> 'NotNull 'PGint4
35− , "email" ::: '[] :=> 'Null 'PGtext
32+ , "emails" :::
33+ '[ "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"] ] :=>
34+ '[ "id" ::: 'Def :=> 'NotNull 'PGint4
35+ , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
36+ , "email" ::: 'NoDef :=> 'Null 'PGtext
3637 ]
3738 ]
3839
@@ -46,8 +47,8 @@ setup =
4647 ( serial `As` #id :*
4748 (int & notNull) `As` #user_id :*
4849 text `As` #email :* Nil )
49− ( foreignKey (Column #user_id :* Nil) #users (Column #id :* Nil)
50− OnDeleteCascade OnUpdateCascade :* Nil )
50+ ( (foreignKey (Column #user_id :* Nil) #users (Column #id :* Nil)
51+ OnDeleteCascade OnUpdateCascade) `As` #fk_user_id :* Nil)
5152
5253teardown :: Definition Schema '[]
5354teardown = dropTable #emails >>> dropTable #users
@@ -55,12 +56,12 @@ teardown = dropTable #emails >>> dropTable #users
5556insertUser :: Manipulation Schema '[ 'NotNull 'PGtext]
5657 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
5758insertUser = insertRows #users
58− (Def `As` #id :* Set (param @1) `As` #name :* Nil) []
59+ (Default `As` #id :* Set (param @1) `As` #name :* Nil) []
5960 OnConflictDoNothing (Returning (#id `As` #fromOnly :* Nil))
6061
6162insertEmail :: Manipulation Schema '[ 'NotNull 'PGint4, 'Null 'PGtext] '[]
6263insertEmail = insertRows #emails
63− ( Def `As` #id :*
64+ ( Default `As` #id :*
6465 Set (param @1) `As` #user_id :*
6566 Set (param @2) `As` #email :* Nil ) []
6667 OnConflictDoNothing (Returning Nil)
squeal-postgresql/squeal-postgresql.cabal+1
@@ -49,6 +49,7 @@ library
4949 , time >= 1.8.0.2 && < 2
5050 , transformers >= 0.5.2.0 && < 1
5151 , transformers-base >= 0.4.4 && < 1
52+ , type-level-sets >= 0.8.5.0 && < 1
5253 , uuid >= 1.3.13 && < 2
5354
5455test-suite squeal-postgresql-spec
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+32−22
@@ -32,8 +32,8 @@ module Squeal.PostgreSQL.Definition
3232 , createTable
3333 , TableConstraintExpression (..)
3434 , check
35− , uniques
36− , primaryKeys
35+ , unique
36+ , primaryKey
3737 , foreignKey
3838 , OnDeleteClause (OnDeleteNoAction, OnDeleteRestrict, OnDeleteCascade)
3939 , renderOnDeleteClause
@@ -64,7 +64,6 @@ import Control.Category
6464import Control.DeepSeq
6565import Data.ByteString
6666import Data.Monoid
67−import Data.Type.Set
6867import GHC.TypeLits
6968import Prelude hiding ((.), id)
7069
@@ -114,7 +113,7 @@ createTable
114113 => Alias tab -- ^ the name of the table to add
115114 -> NP (Aliased TypeExpression) columns
116115 -- ^ the names and datatype of each column
117− -> NP (TableConstraintExpression schema (UnconstrainColumns columns))
116+ -> NP (Aliased (TableConstraintExpression schema (UnconstrainColumns columns)))
118117 constraints
119118 -- ^ constraints that must hold for the table
120119 -> Definition schema (Create tab table schema)
@@ -122,12 +121,17 @@ createTable table columns constraints = UnsafeDefinition $
122121 "CREATE TABLE" <+> renderAlias table
123122 <+> parenthesized
124123 ( renderCommaSeparated renderColumnDef columns
125− <> renderCommaSeparated renderTableConstraintExpression constraints )
124+ <> renderCommaSeparated renderConstraint constraints )
126125 <> ";"
127126 where
128127 renderColumnDef :: Aliased TypeExpression x -> ByteString
129128 renderColumnDef (ty `As` column) =
130129 renderAlias column <+> renderTypeExpression ty
130+ renderConstraint
131+ :: Aliased (TableConstraintExpression schema columns) constraint
132+ -> ByteString
133+ renderConstraint (constraint `As` alias) =
134+ "CONSTRAINT" <+> renderAlias alias <+> renderTableConstraintExpression constraint
131135
132136-- | Data types are a way to limit the kind of data that can be stored in a
133137-- table. For many applications, however, the constraint they provide is
@@ -179,12 +183,12 @@ check condition = UnsafeTableConstraintExpression $
179183-- [ unique (Column #a :* Column #b :* Nil) ]
180184-- :}
181185-- "CREATE TABLE tab (a int, b int, UNIQUE (a, b));"
182−uniques
186+unique
183187 :: SOP.SListI subcolumns
184188 => NP (Column columns) subcolumns
185189 -- ^ unique column or group of columns
186190 -> TableConstraintExpression schema columns ( 'Uniques (Aliases subcolumns))
187−uniques columns = UnsafeTableConstraintExpression $
191+unique columns = UnsafeTableConstraintExpression $
188192 "UNIQUE" <+> parenthesized (renderCommaSeparated renderColumn columns)
189193
190194-- | A `primaryKey` constraint indicates that a column, or group of columns,
@@ -199,12 +203,12 @@ uniques columns = UnsafeTableConstraintExpression $
199203-- [ primaryKey (Column #id :* Nil) ]
200204-- :}
201205-- "CREATE TABLE tab (id serial, name text NOT NULL, PRIMARY KEY (id));"
202−primaryKeys
206+primaryKey
203207 :: (SOP.SListI subcolumns, AllNotNull subcolumns)
204208 => NP (Column columns) subcolumns
205209 -- ^ identifying column or group of columns
206− -> TableConstraintExpression schema columns ('Uniques (Aliases subcolumns))
207−primaryKeys columns = UnsafeTableConstraintExpression $
210+ -> TableConstraintExpression schema columns ('PrimaryKey (Aliases subcolumns))
211+primaryKey columns = UnsafeTableConstraintExpression $
208212 "PRIMARY KEY" <+> parenthesized (renderCommaSeparated renderColumn columns)
209213
210214-- | A `foreignKey` specifies that the values in a column
@@ -369,11 +373,17 @@ alterTableRename table0 table1 = UnsafeDefinition $
369373-- <+> "ADD" <+> renderTableConstraintExpression constraint <> ";"
370374
371375addConstraint
372− :: (tab ::: table) `In` schema
373− => Alias tab
374− -> TableConstraintExpression schema columns constraint
375− -> AlterTable schema table (AddConstraint constraint table)
376−addConstraint = undefined
376+ :: Aliased (TableConstraintExpression schema (UnconstrainColumns columns)) constraint
377+ -> AlterTable schema (constraints :=> columns)
378+ ((constraint ': constraints) :=> columns)
379+addConstraint constraint = UnsafeAlterTable $
380+ "ADD" <+> "CONSTRAINT" <+> renderConstraint constraint
381+ where
382+ renderConstraint
383+ :: Aliased (TableConstraintExpression schema columns) constraint
384+ -> ByteString
385+ renderConstraint (constraint' `As` alias) =
386+ "CONSTRAINT" <+> renderAlias alias <+> renderTableConstraintExpression constraint'
377387
378388-- | An `AlterTable` describes the alteration to perform on the columns
379389-- of a table.
@@ -400,10 +410,10 @@ newtype AlterTable
400410-- :}
401411-- "ALTER TABLE tab ADD COLUMN col2 text DEFAULT E'foo';"
402412addColumnDefault
403− :: (KnownSymbol column, 'Default `In` constraints)
413+ :: KnownSymbol column
404414 => Alias column -- ^ column to add
405− -> TypeExpression (constraints :=> ty) -- ^ type of the new column
406− -> AlterTable schema table (Add column (constraints :=> ty) table)
415+ -> TypeExpression ('Def :=> ty) -- ^ type of the new column
416+ -> AlterTable schema table (Add column ('Def :=> ty) table)
407417addColumnDefault column ty = UnsafeAlterTable $
408418 "ADD COLUMN" <+> renderAlias column <+> renderTypeExpression ty
409419
@@ -424,8 +434,8 @@ addColumnDefault column ty = UnsafeAlterTable $
424434addColumnNull
425435 :: KnownSymbol column
426436 => Alias column -- ^ column to add
427− -> TypeExpression ( '[] :=> 'Null ty) -- ^ type of the new column
428− -> AlterTable schema table (Add column ( '[] :=> 'Null ty) table)
437+ -> TypeExpression ('NoDef :=> 'Null ty) -- ^ type of the new column
438+ -> AlterTable schema table (Add column ('NoDef :=> 'Null ty) table)
429439addColumnNull column ty = UnsafeAlterTable $
430440 "ADD COLUMN" <+> renderAlias column <+> renderTypeExpression ty
431441
@@ -522,7 +532,7 @@ newtype AlterColumn (ty0 :: ColumnType) (ty1 :: ColumnType) =
522532-- "ALTER TABLE tab ALTER COLUMN col SET DEFAULT 5;"
523533setDefault
524534 :: Expression '[] 'Ungrouped '[] ty -- ^ default value to set
525− -> AlterColumn (constraints :=> ty) (AsSet ('Default ': constraints) :=> ty)
535+ -> AlterColumn (constraints :=> ty) ('Def :=> ty)
526536setDefault expression = UnsafeAlterColumn $
527537 "SET DEFAULT" <+> renderExpression expression
528538
@@ -537,7 +547,7 @@ setDefault expression = UnsafeAlterColumn $
537547-- in renderDefinition definition
538548-- :}
539549-- "ALTER TABLE tab ALTER COLUMN col DROP DEFAULT;"
540−dropDefault :: AlterColumn ty (DropConstraint 'Default ty)
550+dropDefault :: AlterColumn ('Def :=> ty) ('NoDef :=> ty)
541551dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
542552
543553-- | A `setNotNull` adds a @NOT NULL@ constraint to a column.
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+28−28
@@ -496,7 +496,7 @@ atan2_ y x = UnsafeExpression $
496496-- | >>> renderExpression $ true & cast int4
497497-- "(TRUE :: int4)"
498498cast
499− :: TypeExpression ('[] :=> 'Null ty1)
499+ :: TypeExpression ('NoDef :=> 'Null ty1)
500500 -- ^ type to cast as
501501 -> Expression tables grouping params (nullity ty0)
502502 -- ^ value to convert
@@ -997,100 +997,100 @@ newtype TypeExpression (ty :: ColumnType)
997997 deriving (GHC.Generic,Show,Eq,Ord,NFData)
998998
999999-- | logical Boolean (true/false)
1000−bool :: TypeExpression ('[] :=> 'Null 'PGbool)
1000+bool :: TypeExpression ('NoDef :=> 'Null 'PGbool)
10011001bool = UnsafeTypeExpression "bool"
10021002-- | signed two-byte integer
1003−int2, smallint :: TypeExpression ('[] :=> 'Null 'PGint2)
1003+int2, smallint :: TypeExpression ('NoDef :=> 'Null 'PGint2)
10041004int2 = UnsafeTypeExpression "int2"
10051005smallint = UnsafeTypeExpression "smallint"
10061006-- | signed four-byte integer
1007−int4, int, integer :: TypeExpression ('[] :=> 'Null 'PGint4)
1007+int4, int, integer :: TypeExpression ('NoDef :=> 'Null 'PGint4)
10081008int4 = UnsafeTypeExpression "int4"
10091009int = UnsafeTypeExpression "int"
10101010integer = UnsafeTypeExpression "integer"
10111011-- | signed eight-byte integer
1012−int8, bigint :: TypeExpression ('[] :=> 'Null 'PGint8)
1012+int8, bigint :: TypeExpression ('NoDef :=> 'Null 'PGint8)
10131013int8 = UnsafeTypeExpression "int8"
10141014bigint = UnsafeTypeExpression "bigint"
10151015-- | arbitrary precision numeric type
1016−numeric :: TypeExpression ('[] :=> 'Null 'PGnumeric)
1016+numeric :: TypeExpression ('NoDef :=> 'Null 'PGnumeric)
10171017numeric = UnsafeTypeExpression "numeric"
10181018-- | single precision floating-point number (4 bytes)
1019−float4, real :: TypeExpression ('[] :=> 'Null 'PGfloat4)
1019+float4, real :: TypeExpression ('NoDef :=> 'Null 'PGfloat4)
10201020float4 = UnsafeTypeExpression "float4"
10211021real = UnsafeTypeExpression "real"
10221022-- | double precision floating-point number (8 bytes)
1023−float8, doublePrecision :: TypeExpression ('[] :=> 'Null 'PGfloat8)
1023+float8, doublePrecision :: TypeExpression ('NoDef :=> 'Null 'PGfloat8)
10241024float8 = UnsafeTypeExpression "float8"
10251025doublePrecision = UnsafeTypeExpression "double precision"
10261026-- | not a true type, but merely a notational convenience for creating
10271027-- unique identifier columns with type `'PGint2`
10281028serial2, smallserial
1029− :: TypeExpression ( AsSet '[ 'Default, 'Unique] :=> 'NotNull 'PGint2)
1029+ :: TypeExpression ('Def :=> 'NotNull 'PGint2)
10301030serial2 = UnsafeTypeExpression "serial2"
10311031smallserial = UnsafeTypeExpression "smallserial"
10321032-- | not a true type, but merely a notational convenience for creating
10331033-- unique identifier columns with type `'PGint4`
10341034serial4, serial
1035− :: TypeExpression ( AsSet '[ 'Default, 'Unique] :=> 'NotNull 'PGint4)
1035+ :: TypeExpression ('Def :=> 'NotNull 'PGint4)
10361036serial4 = UnsafeTypeExpression "serial4"
10371037serial = UnsafeTypeExpression "serial"
10381038-- | not a true type, but merely a notational convenience for creating
10391039-- unique identifier columns with type `'PGint8`
10401040serial8, bigserial
1041− :: TypeExpression ( AsSet '[ 'Default, 'Unique] :=> 'NotNull 'PGint8)
1041+ :: TypeExpression ('Def :=> 'NotNull 'PGint8)
10421042serial8 = UnsafeTypeExpression "serial8"
10431043bigserial = UnsafeTypeExpression "bigserial"
10441044-- | variable-length character string
1045−text :: TypeExpression ('[] :=> 'Null 'PGtext)
1045+text :: TypeExpression ('NoDef :=> 'Null 'PGtext)
10461046text = UnsafeTypeExpression "text"
10471047-- | fixed-length character string
10481048char, character
10491049 :: (KnownNat n, 1 <= n)
10501050 => proxy n
1051− -> TypeExpression ('[] :=> 'Null ('PGchar n))
1051+ -> TypeExpression ('NoDef :=> 'Null ('PGchar n))
10521052char p = UnsafeTypeExpression $ "char(" <> renderNat p <> ")"
10531053character p = UnsafeTypeExpression $ "character(" <> renderNat p <> ")"
10541054-- | variable-length character string
10551055varchar, characterVarying
10561056 :: (KnownNat n, 1 <= n)
10571057 => proxy n
1058− -> TypeExpression ('[] :=> 'Null ('PGvarchar n))
1058+ -> TypeExpression ('NoDef :=> 'Null ('PGvarchar n))
10591059varchar p = UnsafeTypeExpression $ "varchar(" <> renderNat p <> ")"
10601060characterVarying p = UnsafeTypeExpression $
10611061 "character varying(" <> renderNat p <> ")"
10621062-- | binary data ("byte array")
1063−bytea :: TypeExpression ('[] :=> 'Null 'PGbytea)
1063+bytea :: TypeExpression ('NoDef :=> 'Null 'PGbytea)
10641064bytea = UnsafeTypeExpression "bytea"
10651065-- | date and time (no time zone)
1066−timestamp :: TypeExpression ('[] :=> 'Null 'PGtimestamp)
1066+timestamp :: TypeExpression ('NoDef :=> 'Null 'PGtimestamp)
10671067timestamp = UnsafeTypeExpression "timestamp"
10681068-- | date and time, including time zone
1069−timestampWithTimeZone :: TypeExpression ('[] :=> 'Null 'PGtimestamptz)
1069+timestampWithTimeZone :: TypeExpression ('NoDef :=> 'Null 'PGtimestamptz)
10701070timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
10711071-- | calendar date (year, month, day)
1072−date :: TypeExpression ('[] :=> 'Null 'PGdate)
1072+date :: TypeExpression ('NoDef :=> 'Null 'PGdate)
10731073date = UnsafeTypeExpression "date"
10741074-- | time of day (no time zone)
1075−time :: TypeExpression ('[] :=> 'Null 'PGtime)
1075+time :: TypeExpression ('NoDef :=> 'Null 'PGtime)
10761076time = UnsafeTypeExpression "time"
10771077-- | time of day, including time zone
1078−timeWithTimeZone :: TypeExpression ('[] :=> 'Null 'PGtimetz)
1078+timeWithTimeZone :: TypeExpression ('NoDef :=> 'Null 'PGtimetz)
10791079timeWithTimeZone = UnsafeTypeExpression "time with time zone"
10801080-- | time span
1081−interval :: TypeExpression ('[] :=> 'Null 'PGinterval)
1081+interval :: TypeExpression ('NoDef :=> 'Null 'PGinterval)
10821082interval = UnsafeTypeExpression "interval"
10831083-- | universally unique identifier
1084−uuid :: TypeExpression ('[] :=> 'Null 'PGuuid)
1084+uuid :: TypeExpression ('NoDef :=> 'Null 'PGuuid)
10851085uuid = UnsafeTypeExpression "uuid"
10861086-- | IPv4 or IPv6 host address
1087−inet :: TypeExpression ('[] :=> 'Null 'PGinet)
1087+inet :: TypeExpression ('NoDef :=> 'Null 'PGinet)
10881088inet = UnsafeTypeExpression "inet"
10891089-- | textual JSON data
1090−json :: TypeExpression ('[] :=> 'Null 'PGjson)
1090+json :: TypeExpression ('NoDef :=> 'Null 'PGjson)
10911091json = UnsafeTypeExpression "json"
10921092-- | binary JSON data, decomposed
1093−jsonb :: TypeExpression ('[] :=> 'Null 'PGjsonb)
1093+jsonb :: TypeExpression ('NoDef :=> 'Null 'PGjsonb)
10941094jsonb = UnsafeTypeExpression "jsonb"
10951095
10961096-- | used in `createTable` commands as a column constraint to ensure
@@ -1103,14 +1103,14 @@ notNull ty = UnsafeTypeExpression $ renderTypeExpression ty <+> "NOT NULL"
11031103-- | used in `createTable` commands as a column constraint to give a default
11041104default_
11051105 :: Expression '[] 'Ungrouped '[] ty
1106− -> TypeExpression (constraints :=> ty)
1107− -> TypeExpression (AsSet ('Default ': constraints) :=> ty)
1106+ -> TypeExpression ('NoDef :=> ty)
1107+ -> TypeExpression ('Def :=> ty)
11081108default_ x ty = UnsafeTypeExpression $
11091109 renderTypeExpression ty <+> "DEFAULT" <+> renderExpression x
11101110
11111111-- | `pgtype` is a demoted version of a `PGType`
11121112class PGTyped (ty :: PGType) where
1113− pgtype :: TypeExpression ('[] :=> 'Null ty)
1113+ pgtype :: TypeExpression ('NoDef :=> 'Null ty)
11141114instance PGTyped 'PGbool where pgtype = bool
11151115instance PGTyped 'PGint2 where pgtype = int2
11161116instance PGTyped 'PGint4 where pgtype = int4
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+5−7
@@ -201,7 +201,7 @@ insertRows tab row rows conflict returning = UnsafeManipulation $
201201 :: Aliased (ColumnValue '[] params) ty -> ByteString
202202 renderAliasPart (_ `As` name) = renderAlias name
203203 renderColumnValuePart (value `As` _) = case value of
204− Def -> "DEFAULT"
204+ Default -> "DEFAULT"
205205 Set expression -> renderExpression expression
206206
207207insertQuery
@@ -227,12 +227,10 @@ data ColumnValue
227227 (ty :: ColumnType)
228228 where
229229 Same :: ColumnValue (column ': columns) params ty
230− Def
231− :: 'Default `In` constraints
232− => ColumnValue columns params (constraints :=> ty)
230+ Default :: ColumnValue columns params ('Def :=> ty)
233231 Set
234232 :: (forall table. Expression '[table ::: columns] 'Ungrouped params ty)
235− -> ColumnValue columns params (constraints :=> ty)
233+ -> ColumnValue columns params (constraint :=> ty)
236234
237235-- | A `ReturningClause` computes and return value(s) based
238236-- on each row actually inserted, updated or deleted. This is primarily
@@ -301,7 +299,7 @@ renderConflictClause = \case
301299 -> Maybe ByteString
302300 renderUpdate = \case
303301 Same `As` _ -> Nothing
304− Def `As` column -> Just $
302+ Default `As` column -> Just $
305303 renderAlias column <+> "=" <+> "DEFAULT"
306304 Set expression `As` column -> Just $
307305 renderAlias column <+> "=" <+> renderExpression expression
@@ -350,7 +348,7 @@ update table columns wh returning = UnsafeManipulation $
350348 -> Maybe ByteString
351349 renderUpdate = \case
352350 Same `As` _ -> Nothing
353− Def `As` column -> Just $
351+ Default `As` column -> Just $
354352 renderAlias column <+> "=" <+> "DEFAULT"
355353 Set expression `As` column -> Just $
356354 renderAlias column <+> "=" <+> renderExpression expression
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+25−34
@@ -83,10 +83,10 @@ module Squeal.PostgreSQL.Schema
8383 , ColumnConstraint (..)
8484 -- , DropDefault
8585 -- , DropDefaultList
86− , AddConstraint
87− , DropConstraint
86+ -- , AddConstraint
87+ -- , DropConstraint
8888 , TableConstraint (..)
89− , AsSet
89+ -- , AsSet
9090 , Aliases
9191 , Has
9292 ) where
@@ -95,9 +95,9 @@ import Control.DeepSeq
9595import Data.ByteString
9696import Data.Monoid
9797import Data.String
98−import Data.Type.Bool
99−import Data.Type.Equality
100−import Data.Type.Set
98+-- import Data.Type.Bool
99+-- import Data.Type.Equality
100+-- import Data.Type.Set
101101import Generics.SOP (AllZip)
102102import GHC.Generics (Generic)
103103import GHC.Exts
@@ -142,7 +142,7 @@ data NullityType
142142-- is to use `Squeal.PostgreSQL.Expression.def`,
143143-- `Squeal.PostgreSQL.Expression.unDef` or
144144-- `Squeal.PostgreSQL.Expression.param`.
145−type ColumnType = ([ColumnConstraint],NullityType)
145+type ColumnType = (ColumnConstraint,NullityType)
146146
147147-- | `ColumnsType` is a kind synonym for a row of `ColumnType`s.
148148type ColumnsType = [(Symbol,ColumnType)]
@@ -150,11 +150,11 @@ type ColumnsType = [(Symbol,ColumnType)]
150150type RelationType = [(Symbol,NullityType)]
151151type RelationsType = [(Symbol,RelationType)]
152152
153−type TableType = ([TableConstraint],ColumnsType)
153+type TableType = (TableConstraints,ColumnsType)
154154type SchemaType = [(Symbol,TableType)]
155155
156156type family UnconstrainColumn (ty :: ColumnType) :: NullityType where
157− UnconstrainColumn (constraints :=> ty) = ty
157+ UnconstrainColumn (constraint :=> ty) = ty
158158
159159type family UnconstrainColumns (columns :: ColumnsType) :: RelationType where
160160 UnconstrainColumns '[] = '[]
@@ -332,18 +332,18 @@ type family Alter alias xs x where
332332 Alter alias ((alias ::: x0) ': xs) x1 = (alias ::: x1) ': xs
333333 Alter alias (x0 ': xs) x1 = x0 ': Alter alias xs x1
334334
335−type family AddConstraint constraint ty where
336− AddConstraint constraint (constraints :=> ty)
337− = AsSet (constraint ': constraints) :=> ty
335+-- type family AddConstraint constraint ty where
336+-- AddConstraint constraint (constraints :=> ty)
337+-- = AsSet (constraint ': constraints) :=> ty
338338
339−type family DeleteFromList (e :: elem) (list :: [elem]) where
340− DeleteFromList elem '[] = '[]
341− DeleteFromList elem (x ': xs) =
342− If (Cmp elem x == 'EQ) xs (x ': DeleteFromList elem xs)
339+-- type family DeleteFromList (e :: elem) (list :: [elem]) where
340+-- DeleteFromList elem '[] = '[]
341+-- DeleteFromList elem (x ': xs) =
342+-- If (Cmp elem x == 'EQ) xs (x ': DeleteFromList elem xs)
343343
344−type family DropConstraint constraint ty where
345− DropConstraint constraint (constraints :=> ty)
346− = (AsSet (DeleteFromList constraint constraints)) :=> ty
344+-- type family DropConstraint constraint ty where
345+-- DropConstraint constraint (constraints :=> ty)
346+-- = (AsSet (DeleteFromList constraint constraints)) :=> ty
347347
348348-- | @Rename alias0 alias1 xs@ replaces the alias @alias0@ by @alias1@ in @xs@
349349-- and is used in `Squeal.PostgreSQL.Definition.alterTableRename` and
@@ -373,30 +373,21 @@ type family SameFields
373373 columns
374374 = AllZip SameField fields columns
375375
376−type (:=>) (constraints :: [constraint]) ty = '(constraints,ty)
376+type (:=>) (constraints :: constraint) ty = '(constraints,ty)
377377infixr 7 :=>
378378
379379data ColumnConstraint
380− = Default
381− | Unique
382− | References Symbol Symbol
383−
384−type instance Cmp 'Default 'Default = 'EQ
385−type instance Cmp 'Unique 'Unique = 'EQ
386−type instance Cmp ('References tab0 col0) ('References tab1 col1) =
387− If (Cmp tab0 tab1 == 'EQ) (Cmp col0 col1) (Cmp tab0 tab1)
388−type instance Cmp 'Default 'Unique = 'LT
389−type instance Cmp 'Unique 'Default = 'GT
390−type instance Cmp 'Default ('References tab col) = 'LT
391−type instance Cmp ('References tab col) 'Default = 'GT
392−type instance Cmp 'Unique ('References tab col) = 'LT
393−type instance Cmp ('References tab col) 'Unique = 'GT
380+ = Def
381+ | NoDef
394382
395383data TableConstraint
396384 = Check
397385 | Uniques [Symbol]
386+ | PrimaryKey [Symbol]
398387 | ForeignKey [Symbol] Symbol [Symbol]
399388
389+type TableConstraints = [(Symbol,TableConstraint)]
390+
400391type family Aliases xs where
401392 Aliases '[] = '[]
402393 Aliases ((alias ::: x) ': xs) = alias ': Aliases xs
stack.yaml+2
@@ -1,3 +1,5 @@
11resolver: nightly-2017-08-25
22packages:
33- squeal-postgresql
4+extra-deps:
5+- type-level-sets-0.8.5.0