generated from tpl/purs
fix: pin unresult api to rept
This commit is contained in:
parent
43ce1354ea
commit
de1aaccfb6
@ -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)
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user