From de1aaccfb603925b2cbf01ad898c571a42e3e19a Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Fri, 5 Apr 2024 22:14:59 -0500 Subject: [PATCH] fix: pin unresult api to rept --- src/Control.Monad.Postgres.Cursor.purs | 4 ++-- src/Data.Postgres.Unresult.purs | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Control.Monad.Postgres.Cursor.purs b/src/Control.Monad.Postgres.Cursor.purs index ba2142b..a24b218 100644 --- a/src/Control.Monad.Postgres.Cursor.purs +++ b/src/Control.Monad.Postgres.Cursor.purs @@ -8,13 +8,13 @@ import Control.Monad.Error.Class (class MonadError, class MonadThrow) import Control.Monad.Fork.Class (class MonadBracket, class MonadFork, class MonadKill, bracket, kill, never, uninterruptible) import Control.Monad.Postgres.Base (PostgresT, transaction) import Control.Monad.Postgres.Session (class MonadSession, SessionT, exec, exec_, query) -import Control.Monad.Reader (class MonadAsk, class MonadReader, ReaderT, ask, local, mapReader, runReaderT, withReader, withReaderT) +import Control.Monad.Reader (class MonadAsk, class MonadReader, ReaderT, ask, local, runReaderT) import Control.Monad.Trans.Class (class MonadTrans, lift) import Control.Parallel (class Parallel, parallel, sequential) import Data.Array as Array import Data.Maybe (Maybe) import Data.Newtype (class Newtype, unwrap, wrap) -import Data.Postgres (class Deserialize, RepT, deserialize, smash) +import Data.Postgres (RepT, smash) import Data.Postgres.Query (class AsQuery, asQuery) import Data.Postgres.Raw (Raw) import Data.Postgres.Result (class FromRow, fromRow) diff --git a/src/Data.Postgres.Unresult.purs b/src/Data.Postgres.Unresult.purs index 2595cdb..ac1cf8a 100644 --- a/src/Data.Postgres.Unresult.purs +++ b/src/Data.Postgres.Unresult.purs @@ -2,27 +2,26 @@ module Data.Postgres.Unresult where import Prelude -import Control.Monad.Error.Class (class MonadThrow, liftMaybe) +import Control.Monad.Error.Class (liftMaybe) import Control.Monad.State (StateT, runStateT, state) import Data.Array as Array -import Data.Postgres (class Deserialize, deserialize, smash) +import Data.Postgres (class Deserialize, RepT, deserialize, smash) import Data.Postgres.Raw (Raw) import Data.Tuple (fst) import Data.Tuple.Nested ((/\)) -import Effect.Aff (error) -import Effect.Class (class MonadEffect, liftEffect) -import Effect.Exception (Error) +import Effect.Class (liftEffect) +import Foreign (ForeignError(..)) -- | Monad used to incrementally deserialize columns from a row -type UnresultT m a = StateT {ix :: Int, row :: Array Raw} m a +type Unresult a = StateT {ix :: Int, row :: Array Raw} RepT a -- | Run an `UnresultT` -unresult :: forall m a. Monad m => Array Raw -> UnresultT m a -> m a -unresult row m = fst <$> runStateT m {ix: 0, row} +unresult :: forall a. Unresult a -> Array Raw -> RepT a +unresult m row = fst <$> runStateT m {ix: 0, row} -- | Take the next column from the row, unmarshalling into `a` -take :: forall m a. MonadThrow Error m => Deserialize a => MonadEffect m => UnresultT m a +take :: forall a. Deserialize a => Unresult a take = do raw <- state (\r -> Array.index r.row r.ix /\ r {ix = r.ix + 1}) - raw' <- liftMaybe (error "Ran out of columns!") raw + raw' <- liftMaybe (pure $ ForeignError $ "Ran out of columns!") raw liftEffect $ smash $ deserialize raw'