@@ -5,9 +5,17 @@ Copyright: (c) Eitan Chatav, 2017
55Maintainer: eitan@morphism.tech
66Stability: experimental
77
8−`Squeal.PostgreSQL.PQ` is where Squeal statements come to actually get run by
9−`LibPQ`. It contains a `PQ` indexed monad transformer to run `Definition`s and
10−a `MonadPQ` constraint for running a `Manipulation` or `Query`.
8+This module is where Squeal commands actually get executed by
9+`LibPQ`. It containts two typeclasses, `IndexedMonadTransPQ` for executing
10+a `Definition` and `MonadPQ` for executing a `Manipulation` or `Query`,
11+and a `PQ` type with instances for them.
12+
13+Using Squeal in your application will come down to defining
14+the @schema@ of your database and including @PQ schema schema@ in your
15+application's monad transformer stack, giving it an instance of `MonadPQ`.
16+
17+This module also provides functions for retrieving rows from the `LibPQ.Result`
18+of executing Squeal commands.
1119-}
1220
1321{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
@@ -50,12 +58,12 @@ module Squeal.PostgreSQL.PQ
5058 -- * Result
5159 , LibPQ.Result
5260 , LibPQ.Row
61+ , ntuples
5362 , getRow
5463 , getRows
5564 , nextRow
5665 , firstRow
5766 , liftResult
58− , ntuples
5967 , LibPQ.ExecStatus (..)
6068 , resultStatus
6169 , resultErrorMessage
@@ -275,6 +283,8 @@ instance IndexedMonadTransPQ PQ where
275283
276284* `runQueryParams` is like `manipulateParams` for query statements.
277285
286+* `runQuery` is like `runQueryParams` for a parameter-free statement.
287+
278288* `traversePrepared` has the same type signature as a composition of
279289 `traverse` and `manipulateParams` but provides an optimization by
280290 preparing the statement with `LibPQ.prepare` and then traversing a
@@ -300,13 +310,13 @@ class Monad pq => MonadPQ schema pq | pq -> schema where
300310 manipulateParams
301311 :: ToParams x params
302312 => Manipulation schema params ys
303− -- ^ `insertInto`, `update` or `deleteFrom`
313+ -- ^ `insertRows`, `update` or `deleteFrom`
304314 -> x -> pq (K LibPQ.Result ys)
305315 default manipulateParams
306316 :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
307317 => ToParams x params
308318 => Manipulation schema params ys
309− -- ^ `insertInto`, `update` or `deleteFrom`
319+ -- ^ `insertRows`, `update` or `deleteFrom`
310320 -> x -> pq (K LibPQ.Result ys)
311321 manipulateParams manipulation params = lift $
312322 manipulateParams manipulation params
@@ -330,7 +340,7 @@ class Monad pq => MonadPQ schema pq | pq -> schema where
330340 traversePrepared
331341 :: (ToParams x params, Traversable list)
332342 => Manipulation schema params ys
333− -- ^ `insertInto`, `update` or `deleteFrom`
343+ -- ^ `insertRows`, `update`, or `deleteFrom`, and friends
334344 -> list x -> pq (list (K LibPQ.Result ys))
335345 default traversePrepared
336346 :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
@@ -343,20 +353,20 @@ class Monad pq => MonadPQ schema pq | pq -> schema where
343353 :: (ToParams x params, Traversable list)
344354 => list x
345355 -> Manipulation schema params ys
346− -- ^ `insertInto`, `update` or `deleteFrom`
356+ -- ^ `insertRows`, `update` or `deleteFrom`
347357 -> pq (list (K LibPQ.Result ys))
348358 forPrepared = flip traversePrepared
349359
350360 traversePrepared_
351361 :: (ToParams x params, Foldable list)
352362 => Manipulation schema params '[]
353− -- ^ `insertInto`, `update` or `deleteFrom`
363+ -- ^ `insertRows`, `update` or `deleteFrom`
354364 -> list x -> pq ()
355365 default traversePrepared_
356366 :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
357367 => (ToParams x params, Foldable list)
358368 => Manipulation schema params '[]
359− -- ^ `insertInto`, `update` or `deleteFrom`
369+ -- ^ `insertRows`, `update` or `deleteFrom`
360370 -> list x -> pq ()
361371 traversePrepared_ manipulation params = lift $
362372 traversePrepared_ manipulation params
@@ -365,7 +375,7 @@ class Monad pq => MonadPQ schema pq | pq -> schema where
365375 :: (ToParams x params, Foldable list)
366376 => list x
367377 -> Manipulation schema params '[]
368− -- ^ `insertInto`, `update` or `deleteFrom`
378+ -- ^ `insertRows`, `update` or `deleteFrom`
369379 -> pq ()
370380 forPrepared_ = flip traversePrepared_
371381
@@ -511,11 +521,12 @@ instance (MonadBaseControl b m, schema0 ~ schema1)
511521 pqliftWith $ \ run -> liftBaseWith $ \ runInBase -> f $ runInBase . run
512522 restoreM = PQ . const . restoreM
513523
514−-- | Get a row corresponding to a given row number from a `Result`.
524+-- | Get a row corresponding to a given row number from a `LibPQ.Result`,
525+-- throwing an exception if the row number is out of bounds.
515526getRow
516527 :: (FromRow columns y, MonadBase IO io)
517528 => LibPQ.Row
518− -- ^ row
529+ -- ^ row number
519530 -> K LibPQ.Result columns
520531 -- ^ result
521532 -> io y
@@ -532,7 +543,7 @@ getRow r (K result :: K LibPQ.Result columns) = liftBase $ do
532543
533544-- | Intended to be used for unfolding in streaming libraries, `nextRow`
534545-- takes a total number of rows (which can be found with `ntuples`)
535−-- and a `Result` and given a row number if it's too large returns `Nothing`,
546+-- and a `LibPQ.Result` and given a row number if it's too large returns `Nothing`,
536547-- otherwise returning the row along with the next row number.
537548nextRow
538549 :: (FromRow columns y, MonadBase IO io)
@@ -548,7 +559,7 @@ nextRow total (K result :: K LibPQ.Result columns) r
548559 Nothing -> error "nextRow: found unexpected length"
549560 Just row -> return $ Just (r+1, fromRow @columns row)
550561
551−-- | Get all rows from a `Result`.
562+-- | Get all rows from a `LibPQ.Result`.
552563getRows
553564 :: (FromRow columns y, MonadBase IO io)
554565 => K LibPQ.Result columns -- ^ result
@@ -562,7 +573,7 @@ getRows (K result :: K LibPQ.Result columns) = liftBase $ do
562573 Nothing -> error "getRows: found unexpected length"
563574 Just row -> return $ fromRow @columns row
564575
565−-- | Get the first row if possible from a `Result`.
576+-- | Get the first row if possible from a `LibPQ.Result`.
566577firstRow
567578 :: (FromRow columns y, MonadBase IO io)
568579 => K LibPQ.Result columns -- ^ result
@@ -576,7 +587,7 @@ firstRow (K result :: K LibPQ.Result columns) = liftBase $ do
576587 Nothing -> error "firstRow: found unexpected length"
577588 Just row -> return . Just $ fromRow @columns row
578589
579−-- | Lifts actions on results from `LibPQ`.
590+-- | Lifts actions on results from @LibPQ@.
580591liftResult
581592 :: MonadBase IO io
582593 => (LibPQ.Result -> IO x)