@@ -5,7 +5,6 @@
5-- Stability: experimental
5-- Stability: experimental
7-- Squeal is a deep embedding of PostgreSQL in Haskell. Let's see an example!
7-- Squeal is a deep embedding of PostgreSQL in Haskell. Let's see an example!
8−-- FIX DOCS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-- First, we need some language extensions because Squeal uses modern GHC
9-- First, we need some language extensions because Squeal uses modern GHC
11-- features.
10-- features.
@@ -45,13 +44,13 @@
46-- > type Schema =
45-- > type Schema =
47-- > '[ "users" :::
46-- > '[ "users" :::
48−-- > '[ "id" ::: 'Optional ('NotNull 'PGint4)
47+-- > '[ "id" ::: 'Def :=> 'NotNull 'PGint4
49−-- > , "name" ::: 'Required ('NotNull 'PGtext)
48+-- > , "name" ::: 'NoDef :=> 'NotNull 'PGtext
51-- > , "emails" :::
50-- > , "emails" :::
52−-- > '[ "id" ::: 'Optional ('NotNull 'PGint4)
51+-- > '[ "id" ::: 'Def :=> 'NotNull 'PGint4
53−-- > , "user_id" ::: 'Required ('NotNull 'PGint4)
52+-- > , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
54−-- > , "email" ::: 'Required ('Null 'PGtext)
53+-- > , "email" ::: 'NoDef :=> 'Null 'PGtext
@@ -64,18 +63,19 @@
65-- > setup :: Definition '[] Schema
64-- > setup :: Definition '[] Schema
66-- > setup =
65-- > setup =
67−-- > createTable #users
66+-- > createTable #users
68−-- > ( serial `As` #id :*
67+-- > ( serial `As` #id :*
69−-- > (text & notNull) `As` #name :* Nil )
68+-- > (text & notNull) `As` #name :*
69+-- > (vararray int2 & notNull) `As` #vec :* Nil )
70−-- > [ primaryKey (Column #id :* Nil) ]
70+-- > ( primaryKey (Column #id :* Nil) `As` #pk_users :* Nil )
72−-- > createTable #emails
72+-- > createTable #emails
73−-- > ( serial `As` #id :*
73+-- > ( serial `As` #id :*
74−-- > (int & notNull) `As` #user_id :*
74+-- > (int & notNull) `As` #user_id :*
75−-- > text `As` #email :* Nil )
75+-- > text `As` #email :* Nil )
76−-- > [ primaryKey (Column #id :* Nil)
76+-- > ( primaryKey (Column #id :* Nil) `As` #pk_emails :*
77−-- > , foreignKey (Column #user_id :* Nil) #users (Column #id :* Nil)
77+-- > foreignKey (Column #user_id :* Nil) #users (Column #id :* Nil)
78−-- > OnDeleteCascade OnUpdateCascade ]
78+-- > OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
80-- Notice that @setup@ starts with an empty schema @'[]@ and produces @Schema@.
80-- Notice that @setup@ starts with an empty schema @'[]@ and produces @Schema@.
81-- In our `createTable` commands we included `TableConstraint`s to define
81-- In our `createTable` commands we included `TableConstraint`s to define
@@ -97,14 +97,12 @@
97-- of our inserts.
97-- of our inserts.
99-- > insertUser :: Manipulation Schema
99-- > insertUser :: Manipulation Schema
100−-- > '[ 'Required ('NotNull 'PGtext)]
101−-- > '[ "fromOnly" ::: 'Required ('NotNull 'PGint4) ]
100+-- > '[ 'NotNull 'PGtext] '[ "fromOnly" ::: 'NotNull 'PGint4 ]
102-- > insertUser = insertInto #users
101-- > insertUser = insertInto #users
103-- > ( Values (def `As` #id :* param @1 `As` #name :* Nil) [] )
102-- > ( Values (def `As` #id :* param @1 `As` #name :* Nil) [] )
104-- > OnConflictDoNothing (Returning (#id `As` #fromOnly :* Nil))
103-- > OnConflictDoNothing (Returning (#id `As` #fromOnly :* Nil))
106−-- > insertEmail :: Manipulation Schema
105+-- > insertEmail :: Manipulation Schema '[ 'NotNull 'PGint4, 'Null 'PGtext] '[]
107−-- > '[ 'Required ('NotNull 'PGint4), 'Required ('Null 'PGtext)] '[]
108-- > insertEmail = insertInto #emails ( Values
106-- > insertEmail = insertInto #emails ( Values
109-- > ( def `As` #id :*
107-- > ( def `As` #id :*
110-- > param @1 `As` #user_id :*
108-- > param @1 `As` #user_id :*
@@ -117,8 +115,7 @@
117-- `Manipulation` with the same kind of type parameters.
115-- `Manipulation` with the same kind of type parameters.
119-- > getUsers :: Query Schema '[]
117-- > getUsers :: Query Schema '[]
120−-- > '[ "userName" ::: 'Required ('NotNull 'PGtext)
118+-- > '["userName" ::: 'NotNull 'PGtext, "userEmail" ::: 'Null 'PGtext]
121−-- > , "userEmail" ::: 'Required ('Null 'PGtext) ]
122-- > getUsers = select
119-- > getUsers = select
123-- > (#u ! #name `As` #userName :* #e ! #email `As` #userEmail :* Nil)
120-- > (#u ! #name `As` #userName :* #e ! #email `As` #userEmail :* Nil)
124-- > ( from (Table (#users `As` #u)
121-- > ( from (Table (#users `As` #u)