@@ -33,13 +33,13 @@ a `MonadPQ` constraint for running a `Manipulation` or `Query`.
34module Squeal.PostgreSQL.PQ
34module Squeal.PostgreSQL.PQ
35 ( -- * Connection
35 ( -- * Connection
36− Connection (Connection, unConnection)
37− , connectdb
36+ connectdb
39 , withConnection
38 , withConnection
41 , PQ (PQ, runPQ)
40 , PQ (PQ, runPQ)
@@ -51,7 +51,6 @@ module Squeal.PostgreSQL.PQ
52 , pqliftWith
52 , pqliftWith
53 -- * Result
53 -- * Result
54− , Result (Result, unResult)
55 , RowNumber (RowNumber, unRowNumber)
54 , RowNumber (RowNumber, unRowNumber)
56 , ColumnNumber (UnsafeColumnNumber, getColumnNumber)
55 , ColumnNumber (UnsafeColumnNumber, getColumnNumber)
57 , HasColumnNumber (columnNumber)
56 , HasColumnNumber (columnNumber)
@@ -62,6 +61,9 @@ module Squeal.PostgreSQL.PQ
63 , firstRow
62 , firstRow
64 , liftResult
63 , liftResult
67import Control.Exception.Lifted
69import Control.Exception.Lifted
@@ -100,11 +102,6 @@ import qualified Control.Monad.Trans.Writer.Strict as Strict
100import qualified Control.Monad.Trans.RWS.Lazy as Lazy
102import qualified Control.Monad.Trans.RWS.Lazy as Lazy
101import qualified Control.Monad.Trans.RWS.Strict as Strict
103import qualified Control.Monad.Trans.RWS.Strict as Strict
103−-- | A `Connection` consists of a `Database.PostgreSQL.LibPQ`
104−-- `Database.PastgreSQL.LibPQ.Connection` and a phantom `TablesType`
105−newtype Connection (schema :: TablesType) =
106− Connection { unConnection :: LibPQ.Connection }
108{- | Makes a new connection to the database server.
105{- | Makes a new connection to the database server.
110This function opens a new database connection using the parameters taken
107This function opens a new database connection using the parameters taken
@@ -134,19 +131,19 @@ connectdb
134 :: forall schema io
131 :: forall schema io
135 . MonadBase IO io
132 . MonadBase IO io
136 => ByteString -- ^ conninfo
133 => ByteString -- ^ conninfo
137− -> io (Connection schema)
134+ -> io (K LibPQ.Connection schema)
138−connectdb = fmap Connection . liftBase . LibPQ.connectdb
135+connectdb = fmap K . liftBase . LibPQ.connectdb
140-- | Closes the connection to the server.
137-- | Closes the connection to the server.
141−finish :: MonadBase IO io => Connection schema -> io ()
138+finish :: MonadBase IO io => K LibPQ.Connection schema -> io ()
142−finish = liftBase . LibPQ.finish . unConnection
139+finish = liftBase . LibPQ.finish . unK
144-- | Do `connectdb` and `finish` before and after a computation.
141-- | Do `connectdb` and `finish` before and after a computation.
145withConnection
142withConnection
146 :: forall schema0 schema1 io x
143 :: forall schema0 schema1 io x
147 . MonadBaseControl IO io
144 . MonadBaseControl IO io
148 => ByteString
145 => ByteString
149− -> (Connection schema0 -> io (x, Connection schema1))
146+ -> (K LibPQ.Connection schema0 -> io (x, K LibPQ.Connection schema1))
151withConnection connString action = do
148withConnection connString action = do
152 (x, _conn) <- bracket (connectdb connString) finish action
149 (x, _conn) <- bracket (connectdb connString) finish action
@@ -159,16 +156,28 @@ newtype PQ
159 (schema1 :: TablesType)
156 (schema1 :: TablesType)
160 (m :: Type -> Type)
157 (m :: Type -> Type)
161 (x :: Type) =
158 (x :: Type) =
162− PQ { runPQ :: Connection schema0 -> m (x, Connection schema1) }
159+ PQ { runPQ :: K LibPQ.Connection schema0 -> m (K x schema1) }
163− deriving Functor
160+
161+instance Monad m => Functor (PQ schema0 schema1 m) where
162+ fmap f (PQ pq) = PQ $ \ conn -> do
165-- | Run a `PQ` and discard the result but keep the `Connection`.
166-- | Run a `PQ` and discard the result but keep the `Connection`.
167 :: Functor m
168 :: Functor m
168 => PQ schema0 schema1 m x
169 => PQ schema0 schema1 m x
169− -> Connection schema0
170+ -> K LibPQ.Connection schema0
170− -> m (Connection schema1)
171+ -> m (K LibPQ.Connection schema1)
171−execPQ (PQ pq) = fmap snd . pq
172+execPQ (PQ pq) conn = fmap (mapKK (\ _ -> unK conn)) $ pq conn
176+ => PQ schema0 schema1 m x
177+ -> PQ (table ': schema0) (table : schema1) m x
178+pqEmbed (PQ pq) = PQ $ \ (K conn) -> do
173-- | indexed analog of `<*>`
182-- | indexed analog of `<*>`
@@ -177,9 +186,9 @@ pqAp
177 -> PQ schema1 schema2 m x
186 -> PQ schema1 schema2 m x
178 -> PQ schema0 schema2 m y
187 -> PQ schema0 schema2 m y
179pqAp (PQ f) (PQ x) = PQ $ \ conn -> do
188pqAp (PQ f) (PQ x) = PQ $ \ conn -> do
180− (f', conn') <- f conn
189+ K f' <- f conn
181− (x', conn'') <- x conn'
190+ K x' <- x (K (unK conn))
182− return (f' x', conn'')
191+ return $ K (f' x')
184-- | indexed analog of `join`
193-- | indexed analog of `join`
@@ -194,8 +203,8 @@ pqBind
194 -> PQ schema0 schema1 m x
203 -> PQ schema0 schema1 m x
195 -> PQ schema0 schema2 m y
204 -> PQ schema0 schema2 m y
196pqBind f (PQ x) = PQ $ \ conn -> do
205pqBind f (PQ x) = PQ $ \ conn -> do
197− (x', conn') <- x conn
206+ K x' <- x conn
198− runPQ (f x') conn'
207+ runPQ (f x') (K (unK conn))
200-- | indexed analog of flipped `>>`
209-- | indexed analog of flipped `>>`
@@ -211,20 +220,20 @@ pqThen pq2 pq1 = pq1 & pqBind (\ _ -> pq2)
212 :: MonadBase IO io
221 :: MonadBase IO io
213 => Definition schema0 schema1
222 => Definition schema0 schema1
214− -> PQ schema0 schema1 io (Result '[])
223+ -> PQ schema0 schema1 io (K LibPQ.Result '[])
215−define (UnsafeDefinition q) = PQ $ \ (Connection conn) -> do
224+define (UnsafeDefinition q) = PQ $ \ (K conn) -> do
216 resultMaybe <- liftBase $ LibPQ.exec conn q
225 resultMaybe <- liftBase $ LibPQ.exec conn q
217 case resultMaybe of
226 case resultMaybe of
218 Nothing -> error
227 Nothing -> error
219 "define: LibPQ.exec returned no results"
228 "define: LibPQ.exec returned no results"
220− Just result -> return (Result result, Connection conn)
229+ Just result -> return $ K (K result)
222-- | Chain together `define` actions.
231-- | Chain together `define` actions.
223thenDefine
232thenDefine
224 :: MonadBase IO io
233 :: MonadBase IO io
225 => Definition schema1 schema2
234 => Definition schema1 schema2
226 -> PQ schema0 schema1 io x
235 -> PQ schema0 schema1 io x
227− -> PQ schema0 schema2 io (Result '[])
236+ -> PQ schema0 schema2 io (K LibPQ.Result '[])
228thenDefine = pqThen . define
237thenDefine = pqThen . define
230{- | `MonadPQ` is an `mtl` style constraint, similar to
239{- | `MonadPQ` is an `mtl` style constraint, similar to
@@ -264,41 +273,41 @@ class Monad pq => MonadPQ schema pq | pq -> schema where
264 :: ToParams x params
273 :: ToParams x params
265 => Manipulation schema params ys
274 => Manipulation schema params ys
266 -- ^ `insertInto`, `update` or `deleteFrom`
275 -- ^ `insertInto`, `update` or `deleteFrom`
267− -> x -> pq (Result ys)
276+ -> x -> pq (K LibPQ.Result ys)
268 default manipulateParams
277 default manipulateParams
269 :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
278 :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
270 => ToParams x params
279 => ToParams x params
271 => Manipulation schema params ys
280 => Manipulation schema params ys
272 -- ^ `insertInto`, `update` or `deleteFrom`
281 -- ^ `insertInto`, `update` or `deleteFrom`
273− -> x -> pq (Result ys)
282+ -> x -> pq (K LibPQ.Result ys)
274 manipulateParams manipulation params = lift $
283 manipulateParams manipulation params = lift $
275 manipulateParams manipulation params
284 manipulateParams manipulation params
277− manipulate :: Manipulation schema '[] ys -> pq (Result ys)
286+ manipulate :: Manipulation schema '[] ys -> pq (K LibPQ.Result ys)
278 manipulate statement = manipulateParams statement ()
287 manipulate statement = manipulateParams statement ()
280 runQueryParams
289 runQueryParams
281 :: ToParams x params
290 :: ToParams x params
282 => Query schema params ys
291 => Query schema params ys
283 -- ^ `select` and friends
292 -- ^ `select` and friends
284− -> x -> pq (Result ys)
293+ -> x -> pq (K LibPQ.Result ys)
285 runQueryParams = manipulateParams . queryStatement
294 runQueryParams = manipulateParams . queryStatement
288 :: Query schema '[] ys
297 :: Query schema '[] ys
289 -- ^ `select` and friends
298 -- ^ `select` and friends
290− -> pq (Result ys)
299+ -> pq (K LibPQ.Result ys)
291 runQuery q = runQueryParams q ()
300 runQuery q = runQueryParams q ()
293 traversePrepared
302 traversePrepared
294 :: (ToParams x params, Traversable list)
303 :: (ToParams x params, Traversable list)
295 => Manipulation schema params ys
304 => Manipulation schema params ys
296 -- ^ `insertInto`, `update` or `deleteFrom`
305 -- ^ `insertInto`, `update` or `deleteFrom`
297− -> list x -> pq (list (Result ys))
306+ -> list x -> pq (list (K LibPQ.Result ys))
298 default traversePrepared
307 default traversePrepared
299 :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
308 :: (MonadTrans t, MonadPQ schema pq1, pq ~ t pq1)
300 => (ToParams x params, Traversable list)
309 => (ToParams x params, Traversable list)
301− => Manipulation schema params ys -> list x -> pq (list (Result ys))
310+ => Manipulation schema params ys -> list x -> pq (list (K LibPQ.Result ys))
302 traversePrepared manipulation params = lift $
311 traversePrepared manipulation params = lift $
303 traversePrepared manipulation params
312 traversePrepared manipulation params
@@ -307,7 +316,7 @@ class Monad pq => MonadPQ schema pq | pq -> schema where
307 => list x
316 => list x
308 -> Manipulation schema params ys
317 -> Manipulation schema params ys
309 -- ^ `insertInto`, `update` or `deleteFrom`
318 -- ^ `insertInto`, `update` or `deleteFrom`
310− -> pq (list (Result ys))
319+ -> pq (list (K LibPQ.Result ys))
311 forPrepared = flip traversePrepared
320 forPrepared = flip traversePrepared
313 traversePrepared_
322 traversePrepared_
@@ -342,7 +351,7 @@ instance MonadBase IO io => MonadPQ schema (PQ schema schema io) where
343 manipulateParams
352 manipulateParams
344 (UnsafeManipulation q :: Manipulation schema ps ys) (params :: x) =
353 (UnsafeManipulation q :: Manipulation schema ps ys) (params :: x) =
345− PQ $ \ (Connection conn) -> do
354+ PQ $ \ (K conn) -> do
347 toParam' bytes = (LibPQ.invalidOid,bytes,LibPQ.Binary)
356 toParam' bytes = (LibPQ.invalidOid,bytes,LibPQ.Binary)
348 params' = fmap (fmap toParam') (hcollapse (toParams @x @ps params))
357 params' = fmap (fmap toParam') (hcollapse (toParams @x @ps params))
@@ -350,11 +359,11 @@ instance MonadBase IO io => MonadPQ schema (PQ schema schema io) where
350 case resultMaybe of
359 case resultMaybe of
351 Nothing -> error
360 Nothing -> error
352 "manipulateParams: LibPQ.execParams returned no results"
361 "manipulateParams: LibPQ.execParams returned no results"
353− Just result -> return (Result result, Connection conn)
362+ Just result -> return $ K (K result)
355 traversePrepared
364 traversePrepared
356 (UnsafeManipulation q :: Manipulation schema xs ys) (list :: list x) =
365 (UnsafeManipulation q :: Manipulation schema xs ys) (list :: list x) =
357− PQ $ \ (Connection conn) -> liftBase $ do
366+ PQ $ \ (K conn) -> liftBase $ do
358 let temp = "temporary_statement"
367 let temp = "temporary_statement"
359 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
368 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
360 case prepResultMaybe of
369 case prepResultMaybe of
@@ -372,7 +381,7 @@ instance MonadBase IO io => MonadPQ schema (PQ schema schema io) where
372 case resultMaybe of
381 case resultMaybe of
373 Nothing -> error
382 Nothing -> error
374 "traversePrepared: LibPQ.execParams returned no results"
383 "traversePrepared: LibPQ.execParams returned no results"
375− Just result -> return $ Result result
384+ Just result -> return $ K result
376 deallocResultMaybe <- LibPQ.exec conn ("DEALLOCATE " <> temp <> ";")
385 deallocResultMaybe <- LibPQ.exec conn ("DEALLOCATE " <> temp <> ";")
377 case deallocResultMaybe of
386 case deallocResultMaybe of
378 Nothing -> error
387 Nothing -> error
@@ -381,11 +390,11 @@ instance MonadBase IO io => MonadPQ schema (PQ schema schema io) where
381 status <- LibPQ.resultStatus deallocResult
390 status <- LibPQ.resultStatus deallocResult
382 unless (status == LibPQ.CommandOk) . error $
391 unless (status == LibPQ.CommandOk) . error $
383 "traversePrepared: DEALLOCATE status " <> show status
392 "traversePrepared: DEALLOCATE status " <> show status
384− return (results, Connection conn)
393+ return (K results)
386 traversePrepared_
395 traversePrepared_
387 (UnsafeManipulation q :: Manipulation schema xs '[]) (list :: list x) =
396 (UnsafeManipulation q :: Manipulation schema xs '[]) (list :: list x) =
388− PQ $ \ (Connection conn) -> liftBase $ do
397+ PQ $ \ (K conn) -> liftBase $ do
389 let temp = "temporary_statement"
398 let temp = "temporary_statement"
390 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
399 prepResultMaybe <- LibPQ.prepare conn temp q Nothing
391 case prepResultMaybe of
400 case prepResultMaybe of
@@ -412,11 +421,11 @@ instance MonadBase IO io => MonadPQ schema (PQ schema schema io) where
412 status <- LibPQ.resultStatus deallocResult
421 status <- LibPQ.resultStatus deallocResult
413 unless (status == LibPQ.CommandOk) . error $
422 unless (status == LibPQ.CommandOk) . error $
414 "traversePrepared: DEALLOCATE status " <> show status
423 "traversePrepared: DEALLOCATE status " <> show status
415− return ((), Connection conn)
424+ return (K ())
417− liftPQ pq = PQ $ \ (Connection conn) -> do
426+ liftPQ pq = PQ $ \ (K conn) -> do
418 y <- liftBase $ pq conn
427 y <- liftBase $ pq conn
419− return (y, Connection conn)
428+ return (K y)
421instance MonadPQ schema m => MonadPQ schema (IdentityT m)
430instance MonadPQ schema m => MonadPQ schema (IdentityT m)
422instance MonadPQ schema m => MonadPQ schema (ReaderT r m)
431instance MonadPQ schema m => MonadPQ schema (ReaderT r m)
@@ -432,7 +441,7 @@ instance MonadPQ schema m => MonadPQ schema (ContT r m)
432instance MonadPQ schema m => MonadPQ schema (ListT m)
441instance MonadPQ schema m => MonadPQ schema (ListT m)
434instance Monad m => Applicative (PQ schema schema m) where
443instance Monad m => Applicative (PQ schema schema m) where
435− pure x = PQ $ \ conn -> pure (x, conn)
444+ pure x = PQ $ \ _conn -> pure (K x)
436 (<*>) = pqAp
445 (<*>) = pqAp
438instance Monad m => Monad (PQ schema schema m) where
447instance Monad m => Monad (PQ schema schema m) where
@@ -440,34 +449,28 @@ instance Monad m => Monad (PQ schema schema m) where
440 (>>=) = flip pqBind
449 (>>=) = flip pqBind
442instance MonadTrans (PQ schema schema) where
451instance MonadTrans (PQ schema schema) where
443− lift m = PQ $ \ conn -> do
452+ lift m = PQ $ \ _conn -> do
445− return (x, conn)
454+ return (K x)
447instance MonadBase b m => MonadBase b (PQ schema schema m) where
456instance MonadBase b m => MonadBase b (PQ schema schema m) where
448 liftBase = lift . liftBase
457 liftBase = lift . liftBase
450-- | A snapshot of the state of a `PQ` computation.
459-- | A snapshot of the state of a `PQ` computation.
451type PQRun schema =
460type PQRun schema =
452− forall m x. Monad m => PQ schema schema m x -> m (x, Connection schema)
461+ forall m x. Monad m => PQ schema schema m x -> m (K x schema)
454-- | Helper function in defining `MonadBaseControl` instance for `PQ`.
463-- | Helper function in defining `MonadBaseControl` instance for `PQ`.
455pqliftWith :: Functor m => (PQRun schema -> m a) -> PQ schema schema m a
464pqliftWith :: Functor m => (PQRun schema -> m a) -> PQ schema schema m a
456pqliftWith f = PQ $ \ conn ->
465pqliftWith f = PQ $ \ conn ->
457− fmap (\ x -> (x, conn)) (f $ \ pq -> runPQ pq conn)
466+ fmap K (f $ \ pq -> runPQ pq conn)
459instance MonadBaseControl b m => MonadBaseControl b (PQ schema schema m) where
468instance MonadBaseControl b m => MonadBaseControl b (PQ schema schema m) where
460− type StM (PQ schema schema m) x = StM m (x, Connection schema)
469+ type StM (PQ schema schema m) x = StM m (K x schema)
461 liftBaseWith f =
470 liftBaseWith f =
462 pqliftWith $ \ run -> liftBaseWith $ \ runInBase -> f $ runInBase . run
471 pqliftWith $ \ run -> liftBaseWith $ \ runInBase -> f $ runInBase . run
463 restoreM = PQ . const . restoreM
472 restoreM = PQ . const . restoreM
465−-- | Encapsulates the result of a squeal command run by @LibPQ@.
466−-- `Result`s are parameterized by a `ColumnsType` describing the column names
468−newtype Result (columns :: RelationType)
469− = Result { unResult :: LibPQ.Result }
471-- | Just newtypes around a `CInt`
474-- | Just newtypes around a `CInt`
472newtype RowNumber = RowNumber { unRowNumber :: LibPQ.Row }
475newtype RowNumber = RowNumber { unRowNumber :: LibPQ.Row }
@@ -494,12 +497,12 @@ getValue
494 :: (FromColumnValue colty y, MonadBase IO io)
497 :: (FromColumnValue colty y, MonadBase IO io)
495 => RowNumber -- ^ row
498 => RowNumber -- ^ row
496 -> ColumnNumber n columns colty -- ^ col
499 -> ColumnNumber n columns colty -- ^ col
497− -> Result columns -- ^ result
500+ -> K LibPQ.Result columns -- ^ result
500 (RowNumber r)
503 (RowNumber r)
501 (UnsafeColumnNumber c :: ColumnNumber n columns colty)
504 (UnsafeColumnNumber c :: ColumnNumber n columns colty)
502− (Result result)
505+ (K result)
503 = fmap (fromColumnValue @colty . K) $ liftBase $ do
506 = fmap (fromColumnValue @colty . K) $ liftBase $ do
504 numRows <- LibPQ.ntuples result
507 numRows <- LibPQ.ntuples result
505 when (numRows < r) $ error $
508 when (numRows < r) $ error $
@@ -512,10 +515,10 @@ getRow
512 :: (FromRow columns y, MonadBase IO io)
515 :: (FromRow columns y, MonadBase IO io)
513 => RowNumber
516 => RowNumber
515− -> Result columns
518+ -> K LibPQ.Result columns
516 -- ^ result
519 -- ^ result
518−getRow (RowNumber r) (Result result :: Result columns) = liftBase $ do
521+getRow (RowNumber r) (K result :: K LibPQ.Result columns) = liftBase $ do
519 numRows <- LibPQ.ntuples result
522 numRows <- LibPQ.ntuples result
520 when (numRows < r) $ error $
523 when (numRows < r) $ error $
521 "getRow: expected at least " <> show r <> "rows but only saw "
524 "getRow: expected at least " <> show r <> "rows but only saw "
@@ -527,8 +530,8 @@ getRow (RowNumber r) (Result result :: Result columns) = liftBase $ do
527 Just row -> return $ fromRow @columns row
530 Just row -> return $ fromRow @columns row
529-- | Returns the number of rows (tuples) in the query result.
532-- | Returns the number of rows (tuples) in the query result.
530−ntuples :: MonadBase IO io => Result columns -> io RowNumber
533+ntuples :: MonadBase IO io => K LibPQ.Result columns -> io RowNumber
531−ntuples (Result result) = liftBase $ RowNumber <$> LibPQ.ntuples result
534+ntuples (K result) = liftBase $ RowNumber <$> LibPQ.ntuples result
533-- | Intended to be used for unfolding in streaming libraries, `nextRow`
536-- | Intended to be used for unfolding in streaming libraries, `nextRow`
534-- takes a total number of rows (which can be found with `ntuples`)
537-- takes a total number of rows (which can be found with `ntuples`)
@@ -537,10 +540,10 @@ ntuples (Result result) = liftBase $ RowNumber <$> LibPQ.ntuples result
538 :: (FromRow columns y, MonadBase IO io)
541 :: (FromRow columns y, MonadBase IO io)
539 => RowNumber -- ^ total number of rows
542 => RowNumber -- ^ total number of rows
540− -> Result columns -- ^ result
543+ -> K LibPQ.Result columns -- ^ result
541 -> RowNumber -- ^ row number
544 -> RowNumber -- ^ row number
542 -> io (Maybe (RowNumber,y))
545 -> io (Maybe (RowNumber,y))
543−nextRow (RowNumber total) (Result result :: Result columns) (RowNumber r)
546+nextRow (RowNumber total) (K result :: K LibPQ.Result columns) (RowNumber r)
544 = liftBase $ if r >= total then return Nothing else do
547 = liftBase $ if r >= total then return Nothing else do
545 let len = fromIntegral (lengthSList (Proxy @columns))
548 let len = fromIntegral (lengthSList (Proxy @columns))
546 row' <- traverse (LibPQ.getvalue result r) [0 .. len - 1]
549 row' <- traverse (LibPQ.getvalue result r) [0 .. len - 1]
@@ -551,9 +554,9 @@ nextRow (RowNumber total) (Result result :: Result columns) (RowNumber r)
551-- | Get all rows from a `Result`.
554-- | Get all rows from a `Result`.
553 :: (FromRow columns y, MonadBase IO io)
556 :: (FromRow columns y, MonadBase IO io)
554− => Result columns -- ^ result
557+ => K LibPQ.Result columns -- ^ result
555 -> io [y]
558 -> io [y]
556−getRows (Result result :: Result columns) = liftBase $ do
559+getRows (K result :: K LibPQ.Result columns) = liftBase $ do
557 let len = fromIntegral (lengthSList (Proxy @columns))
560 let len = fromIntegral (lengthSList (Proxy @columns))
558 numRows <- LibPQ.ntuples result
561 numRows <- LibPQ.ntuples result
559 for [0 .. numRows - 1] $ \ r -> do
562 for [0 .. numRows - 1] $ \ r -> do
@@ -565,9 +568,9 @@ getRows (Result result :: Result columns) = liftBase $ do
565-- | Get the first row if possible from a `Result`.
568-- | Get the first row if possible from a `Result`.
567 :: (FromRow columns y, MonadBase IO io)
570 :: (FromRow columns y, MonadBase IO io)
568− => Result columns -- ^ result
571+ => K LibPQ.Result columns -- ^ result
569 -> io (Maybe y)
572 -> io (Maybe y)
570−firstRow (Result result :: Result columns) = liftBase $ do
573+firstRow (K result :: K LibPQ.Result columns) = liftBase $ do
571 numRows <- LibPQ.ntuples result
574 numRows <- LibPQ.ntuples result
572 if numRows <= 0 then return Nothing else do
575 if numRows <= 0 then return Nothing else do
573 let len = fromIntegral (lengthSList (Proxy @columns))
576 let len = fromIntegral (lengthSList (Proxy @columns))
@@ -580,5 +583,5 @@ firstRow (Result result :: Result columns) = liftBase $ do
580liftResult
583liftResult
581 :: MonadBase IO io
584 :: MonadBase IO io
582 => (LibPQ.Result -> IO x)
585 => (LibPQ.Result -> IO x)
583− -> Result results -> io x
586+ -> K LibPQ.Result results -> io x
584−liftResult f (Result result) = liftBase $ f result
587+liftResult f (K result) = liftBase $ f result