@@ -50,7 +50,6 @@ module Squeal.PostgreSQL.PQ
5050 , PQRun
5151 , pqliftWith
5252 -- * Result
53− , Result (Result, unResult)
5453 , RowNumber (RowNumber, unRowNumber)
5554 , ColumnNumber (UnsafeColumnNumber, getColumnNumber)
5655 , HasColumnNumber (columnNumber)
@@ -211,20 +210,20 @@ pqThen pq2 pq1 = pq1 & pqBind (\ _ -> pq2)
211210define
212211 :: MonadBase IO io
213212 => Definition schema0 schema1
214− -> PQ schema0 schema1 io (Result '[])
213+ -> PQ schema0 schema1 io (K LibPQ.Result '[])
215214define (UnsafeDefinition q) = PQ $ \ (K conn) -> do
216215 resultMaybe <- liftBase $ LibPQ.exec conn q
217216 case resultMaybe of
218217 Nothing -> error
219218 "define: LibPQ.exec returned no results"
220− Just result -> return $ K (Result result)
219+ Just result -> return $ K (K result)
221220
222221-- | Chain together `define` actions.
223222thenDefine
224223 :: MonadBase IO io
225224 => Definition schema1 schema2
226225 -> PQ schema0 schema1 io x
227− -> PQ schema0 schema2 io (Result '[])
226+ -> PQ schema0 schema2 io (K LibPQ.Result '[])
228227thenDefine = pqThen . define
229228
230229{- | `MonadPQ` is an `mtl` style constraint, similar to
@@ -264,41 +263,41 @@ class Monad pq => MonadPQ schema pq | pq -> schema where
264263 :: ToParams x params
265264 => Manipulation schema params ys
266265 -- ^ `insertInto`, `update` or `deleteFrom`
267− -> x -> pq (Result ys)
266+ -> x -> pq (K LibPQ.Result ys)
268267 default manipulateParams
269268 :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
270269 => ToParams x params
271270 => Manipulation schema params ys
272271 -- ^ `insertInto`, `update` or `deleteFrom`
273− -> x -> pq (Result ys)
272+ -> x -> pq (K LibPQ.Result ys)
274273 manipulateParams manipulation params = lift $
275274 manipulateParams manipulation params
276275
277− manipulate :: Manipulation schema '[] ys -> pq (Result ys)
276+ manipulate :: Manipulation schema '[] ys -> pq (K LibPQ.Result ys)
278277 manipulate statement = manipulateParams statement ()
279278
280279 runQueryParams
281280 :: ToParams x params
282281 => Query schema params ys
283282 -- ^ `select` and friends
284− -> x -> pq (Result ys)
283+ -> x -> pq (K LibPQ.Result ys)
285284 runQueryParams = manipulateParams . queryStatement
286285
287286 runQuery
288287 :: Query schema '[] ys
289288 -- ^ `select` and friends
290− -> pq (Result ys)
289+ -> pq (K LibPQ.Result ys)
291290 runQuery q = runQueryParams q ()
292291
293292 traversePrepared
294293 :: (ToParams x params, Traversable list)
295294 => Manipulation schema params ys
296295 -- ^ `insertInto`, `update` or `deleteFrom`
297− -> list x -> pq (list (Result ys))
296+ -> list x -> pq (list (K LibPQ.Result ys))
298297 default traversePrepared
299298 :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
300299 => (ToParams x params, Traversable list)
301− => Manipulation schema params ys -> list x -> pq (list (Result ys))
300+ => Manipulation schema params ys -> list x -> pq (list (K LibPQ.Result ys))
302301 traversePrepared manipulation params = lift $
303302 traversePrepared manipulation params
304303
@@ -307,7 +306,7 @@ class Monad pq => MonadPQ schema pq | pq -> schema where
307306 => list x
308307 -> Manipulation schema params ys
309308 -- ^ `insertInto`, `update` or `deleteFrom`
310− -> pq (list (Result ys))
309+ -> pq (list (K LibPQ.Result ys))
311310 forPrepared = flip traversePrepared
312311
313312 traversePrepared_
@@ -350,7 +349,7 @@ instance MonadBase IO io => MonadPQ schema (PQ schema schema io) where
350349 case resultMaybe of
351350 Nothing -> error
352351 "manipulateParams: LibPQ.execParams returned no results"
353− Just result -> return $ K (Result result)
352+ Just result -> return $ K (K result)
354353
355354 traversePrepared
356355 (UnsafeManipulation q :: Manipulation schema xs ys) (list :: list x) =
@@ -372,7 +371,7 @@ instance MonadBase IO io => MonadPQ schema (PQ schema schema io) where
372371 case resultMaybe of
373372 Nothing -> error
374373 "traversePrepared: LibPQ.execParams returned no results"
375− Just result -> return $ Result result
374+ Just result -> return $ K result
376375 deallocResultMaybe <- LibPQ.exec conn ("DEALLOCATE " <> temp <> ";")
377376 case deallocResultMaybe of
378377 Nothing -> error
@@ -462,12 +461,6 @@ instance MonadBaseControl b m => MonadBaseControl b (PQ schema schema m) where
462461 pqliftWith $ \ run -> liftBaseWith $ \ runInBase -> f $ runInBase . run
463462 restoreM = PQ . const . restoreM
464463
465−-- | Encapsulates the result of a squeal command run by @LibPQ@.
466−-- `Result`s are parameterized by a `ColumnsType` describing the column names
467−-- and their types.
468−newtype Result (columns :: RelationType)
469− = Result { unResult :: LibPQ.Result }
470−
471464-- | Just newtypes around a `CInt`
472465newtype RowNumber = RowNumber { unRowNumber :: LibPQ.Row }
473466
@@ -494,12 +487,12 @@ getValue
494487 :: (FromColumnValue colty y, MonadBase IO io)
495488 => RowNumber -- ^ row
496489 -> ColumnNumber n columns colty -- ^ col
497− -> Result columns -- ^ result
490+ -> K LibPQ.Result columns -- ^ result
498491 -> io y
499492getValue
500493 (RowNumber r)
501494 (UnsafeColumnNumber c :: ColumnNumber n columns colty)
502− (Result result)
495+ (K result)
503496 = fmap (fromColumnValue @colty . K) $ liftBase $ do
504497 numRows <- LibPQ.ntuples result
505498 when (numRows < r) $ error $
@@ -512,10 +505,10 @@ getRow
512505 :: (FromRow columns y, MonadBase IO io)
513506 => RowNumber
514507 -- ^ row
515− -> Result columns
508+ -> K LibPQ.Result columns
516509 -- ^ result
517510 -> io y
518−getRow (RowNumber r) (Result result :: Result columns) = liftBase $ do
511+getRow (RowNumber r) (K result :: K LibPQ.Result columns) = liftBase $ do
519512 numRows <- LibPQ.ntuples result
520513 when (numRows < r) $ error $
521514 "getRow: expected at least " <> show r <> "rows but only saw "
@@ -527,8 +520,8 @@ getRow (RowNumber r) (Result result :: Result columns) = liftBase $ do
527520 Just row -> return $ fromRow @columns row
528521
529522-- | Returns the number of rows (tuples) in the query result.
530−ntuples :: MonadBase IO io => Result columns -> io RowNumber
531−ntuples (Result result) = liftBase $ RowNumber <$> LibPQ.ntuples result
523+ntuples :: MonadBase IO io => K LibPQ.Result columns -> io RowNumber
524+ntuples (K result) = liftBase $ RowNumber <$> LibPQ.ntuples result
532525
533526-- | Intended to be used for unfolding in streaming libraries, `nextRow`
534527-- takes a total number of rows (which can be found with `ntuples`)
@@ -537,10 +530,10 @@ ntuples (Result result) = liftBase $ RowNumber <$> LibPQ.ntuples result
537530nextRow
538531 :: (FromRow columns y, MonadBase IO io)
539532 => RowNumber -- ^ total number of rows
540− -> Result columns -- ^ result
533+ -> K LibPQ.Result columns -- ^ result
541534 -> RowNumber -- ^ row number
542535 -> io (Maybe (RowNumber,y))
543−nextRow (RowNumber total) (Result result :: Result columns) (RowNumber r)
536+nextRow (RowNumber total) (K result :: K LibPQ.Result columns) (RowNumber r)
544537 = liftBase $ if r >= total then return Nothing else do
545538 let len = fromIntegral (lengthSList (Proxy @columns))
546539 row' <- traverse (LibPQ.getvalue result r) [0 .. len - 1]
@@ -551,9 +544,9 @@ nextRow (RowNumber total) (Result result :: Result columns) (RowNumber r)
551544-- | Get all rows from a `Result`.
552545getRows
553546 :: (FromRow columns y, MonadBase IO io)
554− => Result columns -- ^ result
547+ => K LibPQ.Result columns -- ^ result
555548 -> io [y]
556−getRows (Result result :: Result columns) = liftBase $ do
549+getRows (K result :: K LibPQ.Result columns) = liftBase $ do
557550 let len = fromIntegral (lengthSList (Proxy @columns))
558551 numRows <- LibPQ.ntuples result
559552 for [0 .. numRows - 1] $ \ r -> do
@@ -565,9 +558,9 @@ getRows (Result result :: Result columns) = liftBase $ do
565558-- | Get the first row if possible from a `Result`.
566559firstRow
567560 :: (FromRow columns y, MonadBase IO io)
568− => Result columns -- ^ result
561+ => K LibPQ.Result columns -- ^ result
569562 -> io (Maybe y)
570−firstRow (Result result :: Result columns) = liftBase $ do
563+firstRow (K result :: K LibPQ.Result columns) = liftBase $ do
571564 numRows <- LibPQ.ntuples result
572565 if numRows <= 0 then return Nothing else do
573566 let len = fromIntegral (lengthSList (Proxy @columns))
@@ -580,5 +573,5 @@ firstRow (Result result :: Result columns) = liftBase $ do
580573liftResult
581574 :: MonadBase IO io
582575 => (LibPQ.Result -> IO x)
583− -> Result results -> io x
584−liftResult f (Result result) = liftBase $ f result
576+ -> K LibPQ.Result results -> io x
577+liftResult f (K result) = liftBase $ f result