on dev help sign in
fix tests
commitb044fd278dc770fb8d6629c11bcb0e07ccf01eb6 authorEitan Chatav <eitan.chatav@gmail.com> dateThu 10 Jan 2019, 10:43 (8 years ago) parent0131dc7
6 files changed+29−33
squeal-postgresql/src/Squeal/PostgreSQL.hs+2−3 squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+3−3 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+3−4 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+9−9 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+11−11 squeal-postgresql/test/Specs/ExceptionHandling.hs+1−3
squeal-postgresql/src/Squeal/PostgreSQL.hs+2−3
@@ -47,7 +47,6 @@ type Schema =
4747 '[ "users" ::: 'Table (UsersConstraints :=> UsersColumns)
4848 , "emails" ::: 'Table (EmailsConstraints :=> EmailsColumns) ]
4949type Schemas = Public Schema
50−type DB = DBof Schemas
5150:}
5251
5352Notice the use of type operators.
@@ -118,7 +117,7 @@ of our inserts.
118117
119118>>> :{
120119let
121− insertUser :: Manipulation DB '[ 'NotNull 'PGtext, 'Null 'PGtext ] '[]
120+ insertUser :: Manipulation '[] Schemas '[ 'NotNull 'PGtext, 'Null 'PGtext ] '[]
122121 insertUser = with (u `as` #u) e
123122 where
124123 u = insertInto #users
@@ -138,7 +137,7 @@ need to use an inner join to get the right result. A `Query` is like a
138137
139138>>> :{
140139let
141− getUsers :: Query DB '[]
140+ getUsers :: Query '[] Schemas '[]
142141 '[ "userName" ::: 'NotNull 'PGtext
143142 , "userEmail" ::: 'Null 'PGtext ]
144143 getUsers = select_
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+3−3
@@ -27,7 +27,7 @@ round trip query.
2727>>> instance HasDatatypeInfo Row
2828>>> :{
2929let
30− roundTrip :: Query (DBof (Public '[])) (TuplePG Row) (RowPG Row)
30+ roundTrip :: Query_ (Public '[]) Row Row
3131 roundTrip = values_ $
3232 parameter @1 int2 `as` #col1 :*
3333 parameter @2 text `as` #col2 :*
@@ -68,7 +68,7 @@ Once again, we define a simple round trip query.
6868
6969>>> :{
7070let
71− roundTrip :: Query (DBof (Public '[])) (TuplePG Row) (RowPG Row)
71+ roundTrip :: Query_ (Public '[]) Row Row
7272 roundTrip = values_ $
7373 parameter @1 (int2 & vararray) `as` #col1 :*
7474 parameter @2 (int2 & fixarray @2) `as` #col2 :*
@@ -146,7 +146,7 @@ Once again, define a round trip query.
146146
147147>>> :{
148148let
149− roundTrip :: Query (DBof (Public Schema)) (TuplePG Row) (RowPG Row)
149+ roundTrip :: Query_ (Public Schema) Row Row
150150 roundTrip = values_ $
151151 parameter @1 (typedef #schwarma) `as` #schwarma :*
152152 parameter @2 (typedef #person) `as` #person1 :*
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+3−4
@@ -245,7 +245,7 @@ class KnownNat n => HasParameter
245245 | n params -> ty where
246246 -- | `parameter` takes a `Nat` using type application and a `TypeExpression`.
247247 --
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)
249249 -- >>> printSQL expr
250250 -- ($1 :: int4)
251251 parameter
@@ -420,7 +420,7 @@ matchNull y f x = ifThenElse (isNull x) y
420420`nullIf` gives @NULL@.
421421
422422>>> :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)
424424>>> printSQL expr
425425NULL IF (FALSE, ($1 :: bool))
426426-}
@@ -480,10 +480,9 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
480480-- '[ "real" ::: 'NotNull 'PGfloat8
481481-- , "imaginary" ::: 'NotNull 'PGfloat8 ]
482482-- type Schema = '["complex" ::: 'Typedef Complex]
483−-- type DB = DBof (Public Schema)
484483-- :}
485484--
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)
487486-- >>> printSQL $ i & field #complex #imaginary
488487-- (ROW(0, 1)::"complex")."imaginary"
489488field
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+9−9
@@ -78,7 +78,7 @@ simple insert:
7878>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
7979>>> :{
8080let
81− manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
81+ manipulation :: Manipulation '[] (Public Schema) '[] '[]
8282 manipulation =
8383 insertInto_ #tab (Values_ (2 `as` #col1 :* defaultAs #col2))
8484in printSQL manipulation
@@ -91,7 +91,7 @@ parameterized insert:
9191>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
9292>>> :{
9393let
94− manipulation :: Manipulation (DBof (Public Schema)) '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
94+ manipulation :: Manipulation '[] (Public Schema) '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
9595 manipulation =
9696 insertInto_ #tab (Values_ (param @1 `as` #col1 :* param @2 `as` #col2))
9797in printSQL manipulation
@@ -102,7 +102,7 @@ returning insert:
102102
103103>>> :{
104104let
105− manipulation :: Manipulation (DBof (Public Schema)) '[] '["fromOnly" ::: 'NotNull 'PGint4]
105+ manipulation :: Manipulation '[] (Public Schema) '[] '["fromOnly" ::: 'NotNull 'PGint4]
106106 manipulation =
107107 insertInto #tab (Values_ (2 `as` #col1 :* 3 `as` #col2))
108108 OnConflictDoRaise (Returning (#col1 `as` #fromOnly))
@@ -117,7 +117,7 @@ upsert:
117117>>> type CustomersSchema = '["customers" ::: 'Table (CustomersConstraints :=> CustomersColumns)]
118118>>> :{
119119let
120− manipulation :: Manipulation (DBof (Public CustomersSchema)) '[] '[]
120+ manipulation :: Manipulation '[] (Public CustomersSchema) '[] '[]
121121 manipulation =
122122 insertInto #customers
123123 (Values_ ("John Smith" `as` #name :* "john@smith.com" `as` #email))
@@ -132,7 +132,7 @@ query insert:
132132
133133>>> :{
134134let
135− manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
135+ manipulation :: Manipulation '[] (Public Schema) '[] '[]
136136 manipulation = insertInto_ #tab (Subquery (select Star (from (table #tab))))
137137in printSQL manipulation
138138:}
@@ -142,7 +142,7 @@ update:
142142
143143>>> :{
144144let
145− manipulation :: Manipulation (DBof (Public Schema)) '[] '[]
145+ manipulation :: Manipulation '[] (Public Schema) '[] '[]
146146 manipulation = update_ #tab (2 `as` #col1) (#col1 ./= #col2)
147147in printSQL manipulation
148148:}
@@ -152,7 +152,7 @@ delete:
152152
153153>>> :{
154154let
155− manipulation :: Manipulation (DBof (Public Schema)) '[]
155+ manipulation :: Manipulation '[] (Public Schema) '[]
156156 '[ "col1" ::: 'NotNull 'PGint4
157157 , "col2" ::: 'NotNull 'PGint4 ]
158158 manipulation = deleteFrom #tab NoUsing (#col1 .== #col2) (Returning Star)
@@ -171,7 +171,7 @@ type Schema3 =
171171
172172>>> :{
173173let
174− manipulation :: Manipulation (DBof (Public Schema3)) '[] '[]
174+ manipulation :: Manipulation '[] (Public Schema3) '[] '[]
175175 manipulation =
176176 deleteFrom_ #tab (Using (table #other_tab & also (table #third_tab)))
177177 ( (#tab ! #col2 .== #other_tab ! #col2)
@@ -186,7 +186,7 @@ with manipulation:
186186>>> type ProductsSchema = '["products" ::: 'Table ('[] :=> ProductsColumns), "products_deleted" ::: 'Table ('[] :=> ProductsColumns)]
187187>>> :{
188188let
189− manipulation :: Manipulation (DBof (Public ProductsSchema)) '[ 'NotNull 'PGdate] '[]
189+ manipulation :: Manipulation '[] (Public ProductsSchema) '[ 'NotNull 'PGdate] '[]
190190 manipulation = with
191191 (deleteFrom #products NoUsing (#date .< param @1) (Returning Star) `as` #del)
192192 (insertInto_ #products_deleted (Subquery (select Star (from (common #del)))))
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+11−11
@@ -147,7 +147,7 @@ simple query:
147147>>> type Schema = '["tab" ::: 'Table ('[] :=> Columns)]
148148>>> :{
149149let
150− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
150+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
151151 query = select Star (from (table #tab))
152152in printSQL query
153153:}
@@ -157,7 +157,7 @@ restricted query:
157157
158158>>> :{
159159let
160− query :: Query (DBof (Public Schema)) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4]
160+ query :: Query '[] (Public Schema) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4]
161161 query =
162162 select_ ((#col1 + #col2) `as` #sum :* #col1)
163163 ( from (table #tab)
@@ -171,7 +171,7 @@ subquery:
171171
172172>>> :{
173173let
174− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
174+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
175175 query = select Star (from (subquery (select Star (from (table #tab)) `as` #sub)))
176176in printSQL query
177177:}
@@ -181,7 +181,7 @@ limits and offsets:
181181
182182>>> :{
183183let
184− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
184+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
185185 query = select Star (from (table #tab) & limit 100 & offset 2 & limit 50 & offset 2)
186186in printSQL query
187187:}
@@ -191,7 +191,7 @@ parameterized query:
191191
192192>>> :{
193193let
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]
195195 query = select Star (from (table #tab) & where_ (#col1 .> param @1))
196196in printSQL query
197197:}
@@ -201,7 +201,7 @@ aggregation query:
201201
202202>>> :{
203203let
204− query :: Query (DBof (Public Schema)) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4 ]
204+ query :: Query '[] (Public Schema) '[] '["sum" ::: 'NotNull 'PGint4, "col1" ::: 'NotNull 'PGint4 ]
205205 query =
206206 select_ (sum_ #col2 `as` #sum :* #col1)
207207 ( from (table (#tab `as` #table1))
@@ -215,7 +215,7 @@ sorted query:
215215
216216>>> :{
217217let
218− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
218+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
219219 query = select Star (from (table #tab) & orderBy [#col1 & Asc])
220220in printSQL query
221221:}
@@ -252,7 +252,7 @@ type OrdersSchema =
252252
253253>>> :{
254254let
255− query :: Query (DBof (Public OrdersSchema))
255+ query :: Query '[] (Public OrdersSchema)
256256 '[]
257257 '[ "order_price" ::: 'NotNull 'PGfloat4
258258 , "customer_name" ::: 'NotNull 'PGtext
@@ -275,7 +275,7 @@ self-join:
275275
276276>>> :{
277277let
278− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
278+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
279279 query = select (#t1 & DotStar) (from (table (#tab `as` #t1) & crossJoin (table (#tab `as` #t2))))
280280in printSQL query
281281:}
@@ -295,7 +295,7 @@ set operations:
295295
296296>>> :{
297297let
298− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
298+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
299299 query = select Star (from (table #tab)) `unionAll` select Star (from (table #tab))
300300in printSQL query
301301:}
@@ -305,7 +305,7 @@ with queries:
305305
306306>>> :{
307307let
308− query :: Query (DBof (Public Schema)) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
308+ query :: Query '[] (Public Schema) '[] '["col1" ::: 'NotNull 'PGint4, "col2" ::: 'NotNull 'PGint4]
309309 query = with (
310310 select Star (from (table #tab)) `as` #cte1 :>>
311311 select Star (from (common #cte1)) `as` #cte2
squeal-postgresql/test/Specs/ExceptionHandling.hs+1−3
@@ -48,8 +48,6 @@ type Schema =
4848
4949type Schemas = Public Schema
5050
51−type DB = DBof Schemas
52−
5351data User =
5452 User { userName :: Text
5553 , userEmail :: Maybe Text
@@ -58,7 +56,7 @@ data User =
5856instance SOP.Generic User
5957instance SOP.HasDatatypeInfo User
6058
61−insertUser :: Manipulation DB '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
59+insertUser :: Manipulation '[] Schemas '[ 'NotNull 'PGtext, 'NotNull ('PGvararray ('Null 'PGint2))]
6260 '[ "fromOnly" ::: 'NotNull 'PGint4 ]
6361insertUser = insertInto #users
6462 (Values_ (defaultAs #id :* param @1 `as` #name :* param @2 `as` #vec))