on dev help sign in
fix tests
b044fd2Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL.hs+2−3
@@ -47,7 +47,6 @@ type Schema =
47 '[ "users" ::: 'Table (UsersConstraints :=> UsersColumns)
47 '[ "users" ::: 'Table (UsersConstraints :=> UsersColumns)
48 , "emails" ::: 'Table (EmailsConstraints :=> EmailsColumns) ]
48 , "emails" ::: 'Table (EmailsConstraints :=> EmailsColumns) ]
49type Schemas = Public Schema
49type Schemas = Public Schema
50−type DB = DBof Schemas
51:}
50:}
52
51
53Notice the use of type operators.
52Notice the use of type operators.
@@ -118,7 +117,7 @@ of our inserts.
118
117
119>>> :{
118>>> :{
120let
119let
121− insertUser :: Manipulation DB '[ 'NotNull 'PGtext, 'Null 'PGtext ] '[]
120+ insertUser :: Manipulation '[] Schemas '[ 'NotNull 'PGtext, 'Null 'PGtext ] '[]
122 insertUser = with (u `as` #u) e
121 insertUser = with (u `as` #u) e
123 where
122 where
124 u = insertInto #users
123 u = insertInto #users
@@ -138,7 +137,7 @@ need to use an inner join to get the right result. A `Query` is like a
138
137
139>>> :{
138>>> :{
140let
139let
141− getUsers :: Query DB '[]
140+ getUsers :: Query '[] Schemas '[]
142 '[ "userName" ::: 'NotNull 'PGtext
141 '[ "userName" ::: 'NotNull 'PGtext
143 , "userEmail" ::: 'Null 'PGtext ]
142 , "userEmail" ::: 'Null 'PGtext ]
144 getUsers = select_
143 getUsers = select_
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+3−3
@@ -27,7 +27,7 @@ round trip query.
27>>> instance HasDatatypeInfo Row
27>>> instance HasDatatypeInfo Row
28>>> :{
28>>> :{
29let
29let
30− roundTrip :: Query (DBof (Public '[])) (TuplePG Row) (RowPG Row)
30+ roundTrip :: Query_ (Public '[]) Row Row
31 roundTrip = values_ $
31 roundTrip = values_ $
32 parameter @1 int2 `as` #col1 :*
32 parameter @1 int2 `as` #col1 :*
33 parameter @2 text `as` #col2 :*
33 parameter @2 text `as` #col2 :*
@@ -68,7 +68,7 @@ Once again, we define a simple round trip query.
68
68
69>>> :{
69>>> :{
70let
70let
71− roundTrip :: Query (DBof (Public '[])) (TuplePG Row) (RowPG Row)
71+ roundTrip :: Query_ (Public '[]) Row Row
72 roundTrip = values_ $
72 roundTrip = values_ $
73 parameter @1 (int2 & vararray) `as` #col1 :*
73 parameter @1 (int2 & vararray) `as` #col1 :*
74 parameter @2 (int2 & fixarray @2) `as` #col2 :*
74 parameter @2 (int2 & fixarray @2) `as` #col2 :*
@@ -146,7 +146,7 @@ Once again, define a round trip query.
146
146
147>>> :{
147>>> :{
148let
148let
149− roundTrip :: Query (DBof (Public Schema)) (TuplePG Row) (RowPG Row)
149+ roundTrip :: Query_ (Public Schema) Row Row
150 roundTrip = values_ $
150 roundTrip = values_ $
151 parameter @1 (typedef #schwarma) `as` #schwarma :*
151 parameter @1 (typedef #schwarma) `as` #schwarma :*
152 parameter @2 (typedef #person) `as` #person1 :*
152 parameter @2 (typedef #person) `as` #person1 :*
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+3−4
@@ -245,7 +245,7 @@ class KnownNat n => HasParameter
245 | n params -> ty where
245 | n params -> ty where
246 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
246 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
247 --
247 --
248− -- >>> let expr = parameter @1 int4 :: Expression (DBof schemas) '[ 'Null 'PGint4] grp from ('Null 'PGint4)
248+ -- >>> let expr = parameter @1 int4 :: Expression '[] schemas '[ 'Null 'PGint4] grp from ('Null 'PGint4)
249 -- >>> printSQL expr
249 -- >>> printSQL expr
250 -- ($1 :: int4)
250 -- ($1 :: int4)
251 parameter
251 parameter
@@ -420,7 +420,7 @@ matchNull y f x = ifThenElse (isNull x) y
420`nullIf` gives @NULL@.
420`nullIf` gives @NULL@.
421
421
422>>> :set -XTypeApplications -XDataKinds
422>>> :set -XTypeApplications -XDataKinds
423−>>> let expr = nullIf false (param @1) :: Expression (commons :=> schema) '[ 'NotNull 'PGbool] grp from ('Null 'PGbool)
423+>>> let expr = nullIf false (param @1) :: Expression commons schemas '[ 'NotNull 'PGbool] grp from ('Null 'PGbool)
424>>> printSQL expr
424>>> printSQL expr
425NULL IF (FALSE, ($1 :: bool))
425NULL IF (FALSE, ($1 :: bool))
426-}
426-}
@@ -480,10 +480,9 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
480-- '[ "real" ::: 'NotNull 'PGfloat8
480-- '[ "real" ::: 'NotNull 'PGfloat8
481-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
481-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
482-- type Schema = '["complex" ::: 'Typedef Complex]
482-- type Schema = '["complex" ::: 'Typedef Complex]
483−-- type DB = DBof (Public Schema)
484-- :}
483-- :}
485--
484--
486−-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression DB from grp params ('NotNull Complex)
485+-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression '[] (Public Schema) from grp params ('NotNull Complex)
487-- >>> printSQL $ i & field #complex #imaginary
486-- >>> printSQL $ i & field #complex #imaginary
488-- (ROW(0, 1)::"complex")."imaginary"
487-- (ROW(0, 1)::"complex")."imaginary"
489field
488field
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+9−9
@@ -78,7 +78,7 @@ simple insert:
78>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
78>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
79>>> :{
79>>> :{
80let
80let
81− manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
81+ manipulation :: Manipulation '[] (Public Schema) '[] '[]
82 manipulation =
82 manipulation =
83 insertInto_ #tab (Values_ (2 `as` #col1 :* defaultAs #col2))
83 insertInto_ #tab (Values_ (2 `as` #col1 :* defaultAs #col2))
84in printSQL manipulation
84in printSQL manipulation
@@ -91,7 +91,7 @@ parameterized insert:
91>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
91>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
92>>> :{
92>>> :{
93let
93let
94− manipulation :: Manipulation (DBof (Public Schema)) '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
94+ manipulation :: Manipulation '[] (Public Schema) '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
95 manipulation =
95 manipulation =
96 insertInto_ #tab (Values_ (param @1 `as` #col1 :* param @2 `as` #col2))
96 insertInto_ #tab (Values_ (param @1 `as` #col1 :* param @2 `as` #col2))
97in printSQL manipulation
97in printSQL manipulation
@@ -102,7 +102,7 @@ returning insert:
102
102
103>>> :{
103>>> :{
104let
104let
105− manipulation :: Manipulation (DBof (Public Schema)) '[] '["fromOnly" ::: 'NotNull 'PGint4]
105+ manipulation :: Manipulation '[] (Public Schema) '[] '["fromOnly" ::: 'NotNull 'PGint4]
106 manipulation =
106 manipulation =
107 insertInto #tab (Values_ (2 `as` #col1 :* 3 `as` #col2))
107 insertInto #tab (Values_ (2 `as` #col1 :* 3 `as` #col2))
108 OnConflictDoRaise (Returning (#col1 `as` #fromOnly))
108 OnConflictDoRaise (Returning (#col1 `as` #fromOnly))
@@ -117,7 +117,7 @@ upsert:
117>>> type CustomersSchema = '["customers" ::: 'Table (CustomersConstraints :=> CustomersColumns)]
117>>> type CustomersSchema = '["customers" ::: 'Table (CustomersConstraints :=> CustomersColumns)]
118>>> :{
118>>> :{
119let
119let
120− manipulation :: Manipulation (DBof (Public CustomersSchema)) '[] '[]
120+ manipulation :: Manipulation '[] (Public CustomersSchema) '[] '[]
121 manipulation =
121 manipulation =
122 insertInto #customers
122 insertInto #customers
123 (Values_ ("John Smith" `as` #name :* "john@smith.com" `as` #email))
123 (Values_ ("John Smith" `as` #name :* "john@smith.com" `as` #email))
@@ -132,7 +132,7 @@ query insert:
132
132
133>>> :{
133>>> :{
134let
134let
135− manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
135+ manipulation :: Manipulation '[] (Public Schema) '[] '[]
136 manipulation = insertInto_ #tab (Subquery (select Star (from (table #tab))))
136 manipulation = insertInto_ #tab (Subquery (select Star (from (table #tab))))
137in printSQL manipulation
137in printSQL manipulation
138:}
138:}
@@ -142,7 +142,7 @@ update:
142
142
143>>> :{
143>>> :{
144let
144let
145− manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
145+ manipulation :: Manipulation '[] (Public Schema) '[] '[]
146 manipulation = update_ #tab (2 `as` #col1) (#col1 ./= #col2)
146 manipulation = update_ #tab (2 `as` #col1) (#col1 ./= #col2)
147in printSQL manipulation
147in printSQL manipulation
148:}
148:}
@@ -152,7 +152,7 @@ delete:
152
152
153>>> :{
153>>> :{
154let
154let
155− manipulation :: Manipulation (DBof (Public Schema)) '[]
155+ manipulation :: Manipulation '[] (Public Schema) '[]
156 '[ "col1" ::: 'NotNull 'PGint4
156 '[ "col1" ::: 'NotNull 'PGint4
157 , "col2" ::: 'NotNull 'PGint4 ]
157 , "col2" ::: 'NotNull 'PGint4 ]
158 manipulation = deleteFrom #tab NoUsing (#col1 .== #col2) (Returning Star)
158 manipulation = deleteFrom #tab NoUsing (#col1 .== #col2) (Returning Star)
@@ -171,7 +171,7 @@ type Schema3 =
171
171
172>>> :{
172>>> :{
173let
173let
174− manipulation :: Manipulation (DBof (Public Schema3)) '[] '[]
174+ manipulation :: Manipulation '[] (Public Schema3) '[] '[]
175 manipulation =
175 manipulation =
176 deleteFrom_ #tab (Using (table #other_tab & also (table #third_tab)))
176 deleteFrom_ #tab (Using (table #other_tab & also (table #third_tab)))
177 ( (#tab ! #col2 .== #other_tab ! #col2)
177 ( (#tab ! #col2 .== #other_tab ! #col2)
@@ -186,7 +186,7 @@ with manipulation:
186>>> type ProductsSchema = '["products" ::: 'Table ('[] :=> ProductsColumns), "products_deleted" ::: 'Table ('[] :=> ProductsColumns)]
186>>> type ProductsSchema = '["products" ::: 'Table ('[] :=> ProductsColumns), "products_deleted" ::: 'Table ('[] :=> ProductsColumns)]
187>>> :{
187>>> :{
188let
188let
189− manipulation :: Manipulation (DBof (Public ProductsSchema)) '[ 'NotNull 'PGdate] '[]
189+ manipulation :: Manipulation '[] (Public ProductsSchema) '[ 'NotNull 'PGdate] '[]
190 manipulation = with
190 manipulation = with
191 (deleteFrom #products NoUsing (#date .< param @1) (Returning Star) `as` #del)
191 (deleteFrom #products NoUsing (#date .< param @1) (Returning Star) `as` #del)
192 (insertInto_ #products_deleted (Subquery (select Star (from (common #del)))))
192 (insertInto_ #products_deleted (Subquery (select Star (from (common #del)))))
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+11−11
@@ -147,7 +147,7 @@ simple query:
147>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
147>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
148>>> :{
148>>> :{
149let
149let
150− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
150+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
151 query = select Star (from (table #tab))
151 query = select Star (from (table #tab))
152in printSQL query
152in printSQL query
153:}
153:}
@@ -157,7 +157,7 @@ restricted query:
157
157
158>>> :{
158>>> :{
159let
159let
160− query :: Query (DBof (Public Schema)) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4]
160+ query :: Query '[] (Public Schema) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4]
161 query =
161 query =
162 select_ ((#col1 + #col2) `as` #sum :* #col1)
162 select_ ((#col1 + #col2) `as` #sum :* #col1)
163 ( from (table #tab)
163 ( from (table #tab)
@@ -171,7 +171,7 @@ subquery:
171
171
172>>> :{
172>>> :{
173let
173let
174− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
174+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
175 query = select Star (from (subquery (select Star (from (table #tab)) `as` #sub)))
175 query = select Star (from (subquery (select Star (from (table #tab)) `as` #sub)))
176in printSQL query
176in printSQL query
177:}
177:}
@@ -181,7 +181,7 @@ limits and offsets:
181
181
182>>> :{
182>>> :{
183let
183let
184− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
184+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
185 query = select Star (from (table #tab) & limit 100 & offset 2 & limit 50 & offset 2)
185 query = select Star (from (table #tab) & limit 100 & offset 2 & limit 50 & offset 2)
186in printSQL query
186in printSQL query
187:}
187:}
@@ -191,7 +191,7 @@ parameterized query:
191
191
192>>> :{
192>>> :{
193let
193let
194− query :: Query (DBof (Public Schema)) '[ 'NotNull 'PGint4] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
194+ query :: Query '[] (Public Schema) '[ 'NotNull 'PGint4] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
195 query = select Star (from (table #tab) & where_ (#col1 .> param @1))
195 query = select Star (from (table #tab) & where_ (#col1 .> param @1))
196in printSQL query
196in printSQL query
197:}
197:}
@@ -201,7 +201,7 @@ aggregation query:
201
201
202>>> :{
202>>> :{
203let
203let
204− query :: Query (DBof (Public Schema)) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4 ]
204+ query :: Query '[] (Public Schema) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4 ]
205 query =
205 query =
206 select_ (sum_ #col2 `as` #sum :* #col1)
206 select_ (sum_ #col2 `as` #sum :* #col1)
207 ( from (table (#tab `as` #table1))
207 ( from (table (#tab `as` #table1))
@@ -215,7 +215,7 @@ sorted query:
215
215
216>>> :{
216>>> :{
217let
217let
218− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
218+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
219 query = select Star (from (table #tab) & orderBy [#col1 & Asc])
219 query = select Star (from (table #tab) & orderBy [#col1 & Asc])
220in printSQL query
220in printSQL query
221:}
221:}
@@ -252,7 +252,7 @@ type OrdersSchema =
252
252
253>>> :{
253>>> :{
254let
254let
255− query :: Query (DBof (Public OrdersSchema))
255+ query :: Query '[] (Public OrdersSchema)
256 '[]
256 '[]
257 '[ "order_price" ::: 'NotNull 'PGfloat4
257 '[ "order_price" ::: 'NotNull 'PGfloat4
258 , "customer_name" ::: 'NotNull 'PGtext
258 , "customer_name" ::: 'NotNull 'PGtext
@@ -275,7 +275,7 @@ self-join:
275
275
276>>> :{
276>>> :{
277let
277let
278− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
278+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
279 query = select (#t1 & DotStar) (from (table (#tab `as` #t1) & crossJoin (table (#tab `as` #t2))))
279 query = select (#t1 & DotStar) (from (table (#tab `as` #t1) & crossJoin (table (#tab `as` #t2))))
280in printSQL query
280in printSQL query
281:}
281:}
@@ -295,7 +295,7 @@ set operations:
295
295
296>>> :{
296>>> :{
297let
297let
298− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
298+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
299 query = select Star (from (table #tab)) `unionAll` select Star (from (table #tab))
299 query = select Star (from (table #tab)) `unionAll` select Star (from (table #tab))
300in printSQL query
300in printSQL query
301:}
301:}
@@ -305,7 +305,7 @@ with queries:
305
305
306>>> :{
306>>> :{
307let
307let
308− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
308+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
309 query = with (
309 query = with (
310 select Star (from (table #tab)) `as` #cte1 :>>
310 select Star (from (table #tab)) `as` #cte1 :>>
311 select Star (from (common #cte1)) `as` #cte2
311 select Star (from (common #cte1)) `as` #cte2
squeal-postgresql/test/Specs/ExceptionHandling.hs+1−3
@@ -48,8 +48,6 @@ type Schema =
48
48
49type Schemas = Public Schema
49type Schemas = Public Schema
50
50
51−type DB = DBof Schemas
52−
53data User =
51data User =
54 User { userName :: Text
52 User { userName :: Text
55 , userEmail :: Maybe Text
53 , userEmail :: Maybe Text
@@ -58,7 +56,7 @@ data User =
58instance SOP.Generic User
56instance SOP.Generic User
59instance SOP.HasDatatypeInfo User
57instance SOP.HasDatatypeInfo User
60
58
61−insertUser :: Manipulation DB '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
59+insertUser :: Manipulation '[] Schemas '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
62 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
60 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
63insertUser = insertInto #users
61insertUser = insertInto #users
64 (Values_ (defaultAs #id :* param @1 `as` #name :* param @2 `as` #vec))
62 (Values_ (defaultAs #id :* param @1 `as` #name :* param @2 `as` #vec))