on dev help sign in
fixing tests
commitfbd7a310fcba52cd0d1d4d244d146d6c96444c1e authorEitan Chatav <eitan.chatav@gmail.com> dateMon 9 Apr 2018, 11:59 (9 years ago) parent6cb5916
6 files changed+79−73
squeal-postgresql/exe/Example.hs+4−4 squeal-postgresql/src/Squeal/PostgreSQL.hs+4−4 squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+20−14 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+17−17 squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+17−17 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+17−17
squeal-postgresql/exe/Example.hs+4−4
@@ -25,20 +25,20 @@ import qualified Generics.SOP as SOP
2525import qualified GHC.Generics as GHC
2626
2727type Schema =
28− '[ "users" :::
28+ '[ "users" ::: 'Table (
2929 '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
3030 '[ "id" ::: 'Def :=> 'NotNull 'PGint4
3131 , "name" ::: 'NoDef :=> 'NotNull 'PGtext
3232 , "vec" ::: 'NoDef :=> 'NotNull ('PGvararray 'PGint2)
33− ]
34− , "emails" :::
33+ ])
34+ , "emails" ::: 'Table (
3535 '[ "pk_emails" ::: 'PrimaryKey '["id"]
3636 , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"]
3737 ] :=>
3838 '[ "id" ::: 'Def :=> 'NotNull 'PGint4
3939 , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
4040 , "email" ::: 'NoDef :=> 'Null 'PGtext
41− ]
41+ ])
4242 ]
4343
4444setup :: Definition '[] Schema
squeal-postgresql/src/Squeal/PostgreSQL.hs+4−4
@@ -31,19 +31,19 @@
3131--
3232-- >>> :{
3333-- type Schema =
34−-- '[ "users" :::
34+-- '[ "users" ::: 'Table (
3535-- '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
3636-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
3737-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
38−-- ]
39−-- , "emails" :::
38+-- ])
39+-- , "emails" ::: 'Table (
4040-- '[ "pk_emails" ::: 'PrimaryKey '["id"]
4141-- , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"]
4242-- ] :=>
4343-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
4444-- , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
4545-- , "email" ::: 'NoDef :=> 'Null 'PGtext
46−-- ]
46+-- ])
4747-- ]
4848-- :}
4949--
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+20−14
@@ -135,7 +135,7 @@ createTable tab columns constraints = UnsafeDefinition $
135135--
136136-- >>> :set -XOverloadedLabels -XTypeApplications
137137-- >>> type Table = '[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGfloat4]
138−-- >>> type Schema = '["tab" ::: Table]
138+-- >>> type Schema = '["tab" ::: 'Table Table]
139139-- >>> :{
140140-- renderDefinition
141141-- (createTableIfNotExists #tab (int `As` #a :* real `As` #b :* Nil) Nil :: Definition Schema Schema)
@@ -210,10 +210,10 @@ newtype TableConstraintExpression
210210--
211211-- >>> :{
212212-- type Schema = '[
213−-- "tab" ::: '[ "inequality" ::: 'Check '["a","b"]] :=> '[
213+-- "tab" ::: 'Table ('[ "inequality" ::: 'Check '["a","b"]] :=> '[
214214-- "a" ::: 'NoDef :=> 'NotNull 'PGint4,
215215-- "b" ::: 'NoDef :=> 'NotNull 'PGint4
216−-- ]]
216+-- ])]
217217-- :}
218218--
219219-- >>> :{
@@ -241,10 +241,10 @@ check _cols condition = UnsafeTableConstraintExpression $
241241--
242242-- >>> :{
243243-- type Schema = '[
244−-- "tab" ::: '[ "uq_a_b" ::: 'Unique '["a","b"]] :=> '[
244+-- "tab" ::: 'Table( '[ "uq_a_b" ::: 'Unique '["a","b"]] :=> '[
245245-- "a" ::: 'NoDef :=> 'Null 'PGint4,
246246-- "b" ::: 'NoDef :=> 'Null 'PGint4
247−-- ]]
247+-- ])]
248248-- :}
249249--
250250-- >>> :{
@@ -272,10 +272,10 @@ unique columns = UnsafeTableConstraintExpression $
272272--
273273-- >>> :{
274274-- type Schema = '[
275−-- "tab" ::: '[ "pk_id" ::: 'PrimaryKey '["id"]] :=> '[
275+-- "tab" ::: 'Table ('[ "pk_id" ::: 'PrimaryKey '["id"]] :=> '[
276276-- "id" ::: 'Def :=> 'NotNull 'PGint4,
277277-- "name" ::: 'NoDef :=> 'NotNull 'PGtext
278−-- ]]
278+-- ])]
279279-- :}
280280--
281281-- >>> :{
@@ -305,19 +305,19 @@ primaryKey columns = UnsafeTableConstraintExpression $
305305--
306306-- >>> :{
307307-- type Schema =
308−-- '[ "users" :::
308+-- '[ "users" ::: 'Table (
309309-- '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
310310-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
311311-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
312−-- ]
313−-- , "emails" :::
312+-- ])
313+-- , "emails" ::: 'Table (
314314-- '[ "pk_emails" ::: 'PrimaryKey '["id"]
315315-- , "fk_user_id" ::: 'ForeignKey '["user_id"] "users" '["id"]
316316-- ] :=>
317317-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
318318-- , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
319319-- , "email" ::: 'NoDef :=> 'Null 'PGtext
320−-- ]
320+-- ])
321321-- ]
322322-- :}
323323--
@@ -344,14 +344,14 @@ primaryKey columns = UnsafeTableConstraintExpression $
344344--
345345-- >>> :{
346346-- type Schema =
347−-- '[ "employees" :::
347+-- '[ "employees" ::: 'Table (
348348-- '[ "employees_pk" ::: 'PrimaryKey '["id"]
349349-- , "employees_employer_fk" ::: 'ForeignKey '["employer_id"] "employees" '["id"]
350350-- ] :=>
351351-- '[ "id" ::: 'Def :=> 'NotNull 'PGint4
352352-- , "name" ::: 'NoDef :=> 'NotNull 'PGtext
353353-- , "employer_id" ::: 'NoDef :=> 'Null 'PGint4
354−-- ]
354+-- ])
355355-- ]
356356-- :}
357357--
@@ -454,7 +454,13 @@ DROP statements
454454
455455-- | `dropTable` removes a table from the schema.
456456--
457−-- >>> renderDefinition $ dropTable #muh_table
457+-- >>> :{
458+-- let
459+-- definition :: Definition '["muh_table" ::: 'Table t] '[]
460+-- definition = dropTable #muh_table
461+-- :}
462+--
463+-- >>> renderDefinition definition
458464-- "DROP TABLE \"muh_table\";"
459465dropTable
460466 :: Has table schema ('Table t)
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+17−17
@@ -73,9 +73,9 @@ simple insert:
7373>>> :{
7474let
7575 manipulation :: Manipulation
76− '[ "tab" ::: '[] :=>
76+ '[ "tab" ::: 'Table ('[] :=>
7777 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
78− , "col2" ::: 'Def :=> 'NotNull 'PGint4 ]] '[] '[]
78+ , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])] '[] '[]
7979 manipulation =
8080 insertRow_ #tab (Set 2 `As` #col1 :* Default `As` #col2 :* Nil)
8181in renderManipulation manipulation
@@ -87,9 +87,9 @@ parameterized insert:
8787>>> :{
8888let
8989 manipulation :: Manipulation
90− '[ "tab" ::: '[] :=>
90+ '[ "tab" ::: 'Table ('[] :=>
9191 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
92− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ]]
92+ , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
9393 '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
9494 manipulation =
9595 insertRow_ #tab
@@ -103,9 +103,9 @@ returning insert:
103103>>> :{
104104let
105105 manipulation :: Manipulation
106− '[ "tab" ::: '[] :=>
106+ '[ "tab" ::: 'Table ('[] :=>
107107 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
108− , "col2" ::: 'Def :=> 'NotNull 'PGint4 ]] '[]
108+ , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])] '[]
109109 '["fromOnly" ::: 'NotNull 'PGint4]
110110 manipulation =
111111 insertRow #tab (Set 2 `As` #col1 :* Default `As` #col2 :* Nil)
@@ -119,9 +119,9 @@ upsert:
119119>>> :{
120120let
121121 manipulation :: Manipulation
122− '[ "tab" ::: '[] :=>
122+ '[ "tab" ::: 'Table ('[] :=>
123123 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
124− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ]]
124+ , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
125125 '[] '[ "sum" ::: 'NotNull 'PGint4]
126126 manipulation =
127127 insertRows #tab
@@ -140,14 +140,14 @@ query insert:
140140>>> :{
141141let
142142 manipulation :: Manipulation
143− '[ "tab" ::: '[] :=>
143+ '[ "tab" ::: 'Table ('[] :=>
144144 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
145145 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4
146− ]
147− , "other_tab" ::: '[] :=>
146+ ])
147+ , "other_tab" ::: 'Table ('[] :=>
148148 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
149149 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4
150− ]
150+ ])
151151 ] '[] '[]
152152 manipulation =
153153 insertQuery_ #tab
@@ -161,9 +161,9 @@ update:
161161>>> :{
162162let
163163 manipulation :: Manipulation
164− '[ "tab" ::: '[] :=>
164+ '[ "tab" ::: 'Table ('[] :=>
165165 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
166− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ]] '[] '[]
166+ , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])] '[] '[]
167167 manipulation =
168168 update_ #tab (Set 2 `As` #col1 :* Same `As` #col2 :* Nil)
169169 (#col1 ./= #col2)
@@ -176,9 +176,9 @@ delete:
176176>>> :{
177177let
178178 manipulation :: Manipulation
179− '[ "tab" ::: '[] :=>
179+ '[ "tab" ::: 'Table ('[] :=>
180180 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
181− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ]] '[]
181+ , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])] '[]
182182 '[ "col1" ::: 'NotNull 'PGint4
183183 , "col2" ::: 'NotNull 'PGint4 ]
184184 manipulation = deleteFrom #tab (#col1 .== #col2) ReturningStar
@@ -482,7 +482,7 @@ WITH statements
482482--
483483-- >>> :{
484484-- let
485−-- manipulation :: Manipulation '["products" ::: ProductsTable, "products_deleted" ::: ProductsTable] '[ 'NotNull 'PGdate] '[]
485+-- manipulation :: Manipulation '["products" ::: 'Table ProductsTable, "products_deleted" ::: 'Table ProductsTable] '[ 'NotNull 'PGdate] '[]
486486-- manipulation = with
487487-- (deleteFrom #products (#date .< param @1) ReturningStar `As` #deleted_rows :* Nil)
488488-- (insertQuery_ #products_deleted (selectStar (from (table (#deleted_rows `As` #t)))))
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+17−17
@@ -31,7 +31,7 @@ type EmailsTable =
3131
3232>>> :{
3333let
34− makeUsers :: Migration IO '[] '["users" ::: UsersTable]
34+ makeUsers :: Migration IO '[] '["users" ::: 'Table UsersTable]
3535 makeUsers = Migration
3636 { name = "make users table"
3737 , up = void . define $
@@ -45,8 +45,8 @@ let
4545
4646>>> :{
4747let
48− makeEmails :: Migration IO '["users" ::: UsersTable]
49− '["users" ::: UsersTable, "emails" ::: EmailsTable]
48+ makeEmails :: Migration IO '["users" ::: 'Table UsersTable]
49+ '["users" ::: 'Table UsersTable, "emails" ::: 'Table EmailsTable]
5050 makeEmails = Migration
5151 { name = "make emails table"
5252 , up = void . define $
@@ -68,7 +68,7 @@ Now that we have a couple migrations we can chain them together.
6868>>> :{
6969let
7070 numMigrations
71− :: Has "schema_migrations" schema MigrationsTable
71+ :: Has "schema_migrations" (TablesOf schema) MigrationsTable
7272 => PQ schema schema IO ()
7373 numMigrations = do
7474 result <- runQuery (selectStar (from (table (#schema_migrations `As` #m))))
@@ -175,8 +175,8 @@ migrateUp migration =
175175 :: MonadBaseControl IO io
176176 => AlignedList (Migration io) schema0 schema1
177177 -> PQ
178− ("schema_migrations" ::: MigrationsTable ': schema0)
179− ("schema_migrations" ::: MigrationsTable ': schema1)
178+ ("schema_migrations" ::: 'Table MigrationsTable ': schema0)
179+ ("schema_migrations" ::: 'Table MigrationsTable ': schema1)
180180 io ()
181181 upMigrations = \case
182182 Done -> return ()
@@ -185,8 +185,8 @@ migrateUp migration =
185185 upMigration
186186 :: MonadBase IO io
187187 => Migration io schema0 schema1 -> PQ
188− ("schema_migrations" ::: MigrationsTable ': schema0)
189− ("schema_migrations" ::: MigrationsTable ': schema1)
188+ ("schema_migrations" ::: 'Table MigrationsTable ': schema0)
189+ ("schema_migrations" ::: 'Table MigrationsTable ': schema1)
190190 io ()
191191 upMigration step =
192192 queryExecuted step
@@ -202,8 +202,8 @@ migrateUp migration =
202202 queryExecuted
203203 :: MonadBase IO io
204204 => Migration io schema0 schema1 -> PQ
205− ("schema_migrations" ::: MigrationsTable ': schema0)
206− ("schema_migrations" ::: MigrationsTable ': schema0)
205+ ("schema_migrations" ::: 'Table MigrationsTable ': schema0)
206+ ("schema_migrations" ::: 'Table MigrationsTable ': schema0)
207207 io Row
208208 queryExecuted step = do
209209 result <- runQueryParams selectMigration (Only (name step))
@@ -230,8 +230,8 @@ migrateDown migrations =
230230 downMigrations
231231 :: MonadBaseControl IO io
232232 => AlignedList (Migration io) schema0 schema1 -> PQ
233− ("schema_migrations" ::: MigrationsTable ': schema1)
234− ("schema_migrations" ::: MigrationsTable ': schema0)
233+ ("schema_migrations" ::: 'Table MigrationsTable ': schema1)
234+ ("schema_migrations" ::: 'Table MigrationsTable ': schema0)
235235 io ()
236236 downMigrations = \case
237237 Done -> return ()
@@ -240,8 +240,8 @@ migrateDown migrations =
240240 downMigration
241241 :: MonadBase IO io
242242 => Migration io schema0 schema1 -> PQ
243− ("schema_migrations" ::: MigrationsTable ': schema1)
244− ("schema_migrations" ::: MigrationsTable ': schema0)
243+ ("schema_migrations" ::: 'Table MigrationsTable ': schema1)
244+ ("schema_migrations" ::: 'Table MigrationsTable ': schema0)
245245 io ()
246246 downMigration step =
247247 queryExecuted step
@@ -257,8 +257,8 @@ migrateDown migrations =
257257 queryExecuted
258258 :: MonadBase IO io
259259 => Migration io schema0 schema1 -> PQ
260− ("schema_migrations" ::: MigrationsTable ': schema1)
261− ("schema_migrations" ::: MigrationsTable ': schema1)
260+ ("schema_migrations" ::: 'Table MigrationsTable ': schema1)
261+ ("schema_migrations" ::: 'Table MigrationsTable ': schema1)
262262 io Row
263263 queryExecuted step = do
264264 result <- runQueryParams selectMigration (Only (name step))
@@ -309,7 +309,7 @@ deleteMigration = deleteFrom_ #schema_migrations (#name .== param @1)
309309-- | Selects a `Migration` from the `MigrationsTable`, returning
310310-- the time at which it was executed.
311311selectMigration
312− :: Has "schema_migrations" schema MigrationsTable
312+ :: Has "schema_migrations" (TablesOf schema) MigrationsTable
313313 => Query schema '[ 'NotNull 'PGtext ]
314314 '[ "executed_at" ::: 'NotNull 'PGtimestamptz ]
315315selectMigration = select
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+17−17
@@ -101,7 +101,7 @@ simple query:
101101>>> :{
102102let
103103 query :: Query
104− '["tab" ::: '[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4]]
104+ '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
105105 '[]
106106 '["col" ::: 'Null 'PGint4]
107107 query = selectStar (from (table (#tab `As` #t)))
@@ -114,9 +114,9 @@ restricted query:
114114>>> :{
115115let
116116 query :: Query
117− '[ "tab" ::: '[] :=>
117+ '[ "tab" ::: 'Table ('[] :=>
118118 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
119− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ]]
119+ , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
120120 '[]
121121 '[ "sum" ::: 'NotNull 'PGint4
122122 , "col1" ::: 'NotNull 'PGint4 ]
@@ -135,7 +135,7 @@ subquery:
135135>>> :{
136136let
137137 query :: Query
138− '["tab" ::: '[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4]]
138+ '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
139139 '[]
140140 '["col" ::: 'Null 'PGint4]
141141 query =
@@ -150,7 +150,7 @@ limits and offsets:
150150>>> :{
151151let
152152 query :: Query
153− '["tab" ::: '[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4]]
153+ '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
154154 '[]
155155 '["col" ::: 'Null 'PGint4]
156156 query = selectStar
@@ -164,7 +164,7 @@ parameterized query:
164164>>> :{
165165let
166166 query :: Query
167− '["tab" ::: '[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGfloat8]]
167+ '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGfloat8])]
168168 '[ 'NotNull 'PGfloat8]
169169 '["col" ::: 'NotNull 'PGfloat8]
170170 query = selectStar
@@ -178,9 +178,9 @@ aggregation query:
178178>>> :{
179179let
180180 query :: Query
181− '[ "tab" ::: '[] :=>
181+ '[ "tab" ::: 'Table ('[] :=>
182182 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
183− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ]]
183+ , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
184184 '[]
185185 '[ "sum" ::: 'NotNull 'PGint4
186186 , "col1" ::: 'NotNull 'PGint4 ]
@@ -198,7 +198,7 @@ sorted query:
198198>>> :{
199199let
200200 query :: Query
201− '["tab" ::: '[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4]]
201+ '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
202202 '[]
203203 '["col" ::: 'Null 'PGint4]
204204 query = selectStar
@@ -213,7 +213,7 @@ joins:
213213>>> :{
214214let
215215 query :: Query
216− '[ "orders" :::
216+ '[ "orders" ::: 'Table (
217217 '["pk_orders" ::: PrimaryKey '["id"]
218218 ,"fk_customers" ::: ForeignKey '["customer_id"] "customers" '["id"]
219219 ,"fk_shippers" ::: ForeignKey '["shipper_id"] "shippers" '["id"]] :=>
@@ -221,17 +221,17 @@ let
221221 , "price" ::: 'NoDef :=> 'NotNull 'PGfloat4
222222 , "customer_id" ::: 'NoDef :=> 'NotNull 'PGint4
223223 , "shipper_id" ::: 'NoDef :=> 'NotNull 'PGint4
224− ]
225− , "customers" :::
224+ ])
225+ , "customers" ::: 'Table (
226226 '["pk_customers" ::: PrimaryKey '["id"]] :=>
227227 '[ "id" ::: 'NoDef :=> 'NotNull 'PGint4
228228 , "name" ::: 'NoDef :=> 'NotNull 'PGtext
229− ]
230− , "shippers" :::
229+ ])
230+ , "shippers" ::: 'Table (
231231 '["pk_shippers" ::: PrimaryKey '["id"]] :=>
232232 '[ "id" ::: 'NoDef :=> 'NotNull 'PGint4
233233 , "name" ::: 'NoDef :=> 'NotNull 'PGtext
234− ]
234+ ])
235235 ]
236236 '[]
237237 '[ "order_price" ::: 'NotNull 'PGfloat4
@@ -256,7 +256,7 @@ self-join:
256256>>> :{
257257let
258258 query :: Query
259− '["tab" ::: '[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4]]
259+ '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
260260 '[]
261261 '["col" ::: 'Null 'PGint4]
262262 query = selectDotStar #t1
@@ -270,7 +270,7 @@ set operations:
270270>>> :{
271271let
272272 query :: Query
273− '["tab" ::: '[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4]]
273+ '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
274274 '[]
275275 '["col" ::: 'Null 'PGint4]
276276 query =