on dev help sign in
pq stuff
994dad3Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+16−22
@@ -247,9 +247,9 @@ pureMigration migration = Migration
247
247
248instance Migratory (Terminally PQ IO) where
248instance Migratory (Terminally PQ IO) where
249
249
250− migrateUp migration = unsafePQ $
250+ migrateUp migration = unsafePQ . transactionally_ $ do
251 define createMigrations
251 define createMigrations
252− & pqThen (transactionally_ (upMigrations migration))
252+ upMigrations migration
253
253
254 where
254 where
255
255
@@ -258,30 +258,27 @@ instance Migratory (Terminally PQ IO) where
258 -> PQ MigrationsSchemas MigrationsSchemas IO ()
258 -> PQ MigrationsSchemas MigrationsSchemas IO ()
259 upMigrations = \case
259 upMigrations = \case
260 Done -> return ()
260 Done -> return ()
261− step :>> steps -> upMigration step & pqThen (upMigrations steps)
261+ step :>> steps -> upMigration step >> upMigrations steps
262
262
263 upMigration
263 upMigration
264 :: Migration (Terminally PQ IO) schemas0 schemas1
264 :: Migration (Terminally PQ IO) schemas0 schemas1
265 -> PQ MigrationsSchemas MigrationsSchemas IO ()
265 -> PQ MigrationsSchemas MigrationsSchemas IO ()
266− upMigration step =
266+ upMigration step = do
267− queryExecuted step
267+ executed <- queryExecuted step
268− & pqBind ( \ executed -> unless (executed == 1)
268+ unless (executed == 1) $ do
269− $ unsafePQ (runTerminally (up step))
269+ unsafePQ . runTerminally $ up step
270− & pqThen (manipulateParams insertMigration (Only (name step)))
270+ manipulateParams_ insertMigration (Only (name step))
271− -- insert execution record
272− & pqBind okResult )
273
271
274 queryExecuted
272 queryExecuted
275 :: Migration (Terminally PQ IO) schemas0 schemas1
273 :: Migration (Terminally PQ IO) schemas0 schemas1
276 -> PQ MigrationsSchemas MigrationsSchemas IO Row
274 -> PQ MigrationsSchemas MigrationsSchemas IO Row
277 queryExecuted step = do
275 queryExecuted step = do
278 result <- runQueryParams selectMigration (Only (name step))
276 result <- runQueryParams selectMigration (Only (name step))
279− okResult result
280 ntuples result
277 ntuples result
281
278
282− migrateDown migrations = unsafePQ $
279+ migrateDown migrations = unsafePQ . transactionally_ $ do
283 define createMigrations
280 define createMigrations
284− & pqThen (transactionally_ (downMigrations migrations))
281+ downMigrations migrations
285
282
286 where
283 where
287
284
@@ -290,25 +287,22 @@ instance Migratory (Terminally PQ IO) where
290 -> PQ MigrationsSchemas MigrationsSchemas IO ()
287 -> PQ MigrationsSchemas MigrationsSchemas IO ()
291 downMigrations = \case
288 downMigrations = \case
292 Done -> return ()
289 Done -> return ()
293− step :>> steps -> downMigrations steps & pqThen (downMigration step)
290+ step :>> steps -> downMigrations steps >> downMigration step
294
291
295 downMigration
292 downMigration
296 :: Migration (Terminally PQ IO) schemas0 schemas1
293 :: Migration (Terminally PQ IO) schemas0 schemas1
297 -> PQ MigrationsSchemas MigrationsSchemas IO ()
294 -> PQ MigrationsSchemas MigrationsSchemas IO ()
298− downMigration step =
295+ downMigration step = do
299− queryExecuted step
296+ executed <- queryExecuted step
300− & pqBind ( \ executed -> unless (executed == 0)
297+ unless (executed == 0) $ do
301− $ unsafePQ (runTerminally (down step))
298+ unsafePQ . runTerminally $ down step
302− & pqThen (manipulateParams deleteMigration (Only (name step)))
299+ manipulateParams_ deleteMigration (Only (name step))
303− -- delete execution record
304− & pqBind okResult )
305
300
306 queryExecuted
301 queryExecuted
307 :: Migration (Terminally PQ IO) schemas0 schemas1
302 :: Migration (Terminally PQ IO) schemas0 schemas1
308 -> PQ MigrationsSchemas MigrationsSchemas IO Row
303 -> PQ MigrationsSchemas MigrationsSchemas IO Row
309 queryExecuted step = do
304 queryExecuted step = do
310 result <- runQueryParams selectMigration (Only (name step))
305 result <- runQueryParams selectMigration (Only (name step))
311− okResult result
312 ntuples result
306 ntuples result
313
307
314unsafePQ :: (Functor m) => PQ db0 db1 m x -> PQ db0' db1' m x
308unsafePQ :: (Functor m) => PQ db0 db1 m x -> PQ db0' db1' m x
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+7
@@ -323,6 +323,13 @@ class Monad pq => MonadPQ schemas pq | pq -> schemas where
323 manipulateParams manipulation params = lift $
323 manipulateParams manipulation params = lift $
324 manipulateParams manipulation params
324 manipulateParams manipulation params
325
325
326+ manipulateParams_
327+ :: ToParams x params
328+ => Manipulation '[] schemas params '[]
329+ -- ^ `insertInto`, `update` or `deleteFrom`
330+ -> x -> pq ()
331+ manipulateParams_ q x = void $ manipulateParams q x
332+
326 manipulate :: Manipulation '[] schemas '[] ys -> pq (K LibPQ.Result ys)
333 manipulate :: Manipulation '[] schemas '[] ys -> pq (K LibPQ.Result ys)
327 manipulate statement = manipulateParams statement ()
334 manipulate statement = manipulateParams statement ()
328
335