on dev help sign in
Merge branch 'pgconstraint-nullity' into pgconstraint
5f11e01Eitan Chatav
squeal-postgresql/exe/Example.hs+9−5
@@ -25,12 +25,14 @@ import qualified GHC.Generics as GHC
25
25
26type Schema =
26type Schema =
27 '[ "users" :::
27 '[ "users" :::
28− '[] :=>
28+ '[ "pk_id" ::: 'PrimaryKey '["id"] ] :=>
29 '[ "id" ::: 'Def :=> 'NotNull 'PGint4
29 '[ "id" ::: 'Def :=> 'NotNull 'PGint4
30 , "name" ::: 'NoDef :=> 'NotNull 'PGtext
30 , "name" ::: 'NoDef :=> 'NotNull 'PGtext
31 ]
31 ]
32 , "emails" :::
32 , "emails" :::
33+ '[ "pk_id" ::: 'PrimaryKey '["id"]
33− '[ "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"] ] :=>
34+ , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"]
35+ ] :=>
34 '[ "id" ::: 'Def :=> 'NotNull 'PGint4
36 '[ "id" ::: 'Def :=> 'NotNull 'PGint4
35 , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
37 , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
36 , "email" ::: 'NoDef :=> 'Null 'PGtext
38 , "email" ::: 'NoDef :=> 'Null 'PGtext
@@ -41,14 +43,16 @@ setup :: Definition '[] Schema
41setup =
43setup =
42 createTable #users
44 createTable #users
43 ( serial `As` #id :*
45 ( serial `As` #id :*
44− (text & notNull) `As` #name :* Nil ) Nil
46+ (text & notNull) `As` #name :* Nil )
47+ ( primaryKey (Column #id :* Nil) `As` #pk_id :* Nil )
45 >>>
48 >>>
46 createTable #emails
49 createTable #emails
47 ( serial `As` #id :*
50 ( serial `As` #id :*
48 (int & notNull) `As` #user_id :*
51 (int & notNull) `As` #user_id :*
49 text `As` #email :* Nil )
52 text `As` #email :* Nil )
53+ ( primaryKey (Column #id :* Nil) `As` #pk_id :*
50− ( (foreignKey (Column #user_id :* Nil) #users (Column #id :* Nil)
54+ foreignKey (Column #user_id :* Nil) #users (Column #id :* Nil)
51− OnDeleteCascade OnUpdateCascade) `As` #fk_user_id :* Nil)
55+ OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
52
56
53teardown :: Definition Schema '[]
57teardown :: Definition Schema '[]
54teardown = dropTable #emails >>> dropTable #users
58teardown = dropTable #emails >>> dropTable #users