hasql 1.1 → 1.1.1
raw patch · 11 files changed
+53/−50 lines, 11 filesdep −eitherdep −tasty-smallcheckdep ~QuickCheckdep ~tastydep ~tasty-quickcheckPVP ok
version bump matches the API change (PVP)
Dependencies removed: either, tasty-smallcheck
Dependency ranges changed: QuickCheck, tasty, tasty-quickcheck, transformers
API changes (from Hackage documentation)
Files
- hasql.cabal +5/−7
- library/Hasql/Private/Connection.hs +2/−2
- library/Hasql/Private/Decoders/Result.hs +10/−10
- library/Hasql/Private/Decoders/Results.hs +6/−6
- library/Hasql/Private/Decoders/Row.hs +4/−4
- library/Hasql/Private/IO.hs +3/−3
- library/Hasql/Private/Prelude.hs +13/−8
- library/Hasql/Private/Query.hs +2/−2
- library/Hasql/Private/Session.hs +3/−3
- tasty/Main/Connection.hs +2/−2
- tasty/Main/DSL.hs +3/−3
hasql.cabal view
@@ -1,7 +1,7 @@ name: hasql version:- 1.1+ 1.1.1 category: Hasql, Database, PostgreSQL synopsis:@@ -93,7 +93,6 @@ profunctors >= 5.1 && < 6, contravariant-extras == 0.3.*, contravariant >= 1.3 && < 2,- either >= 4.4.1 && < 5, mtl >= 2 && < 3, transformers >= 0.3 && < 0.6, -- errors:@@ -124,12 +123,11 @@ -- database: hasql, -- testing:- tasty == 0.11.*,- tasty-quickcheck == 0.8.*,- tasty-smallcheck == 0.8.*,- tasty-hunit == 0.9.*,+ tasty >= 0.12 && < 0.13,+ tasty-quickcheck >= 0.9 && < 0.10,+ tasty-hunit >= 0.9 && < 0.10, quickcheck-instances >= 0.3.11 && < 0.4,- QuickCheck >= 2.8.1 && < 2.10,+ QuickCheck >= 2.8.1 && < 3, -- general: data-default-class, --
library/Hasql/Private/Connection.hs view
@@ -25,9 +25,9 @@ acquire :: Settings.Settings -> IO (Either ConnectionError Connection) acquire settings = {-# SCC "acquire" #-}- runEitherT $ do+ runExceptT $ do pqConnection <- lift (IO.acquireConnection settings)- lift (IO.checkConnectionStatus pqConnection) >>= traverse left+ lift (IO.checkConnectionStatus pqConnection) >>= traverse throwError lift (IO.initConnection pqConnection) integerDatetimes <- lift (IO.getIntegerDatetimes pqConnection) registry <- lift (IO.acquirePreparedStatementRegistry)
library/Hasql/Private/Decoders/Result.hs view
@@ -11,7 +11,7 @@ newtype Result a =- Result (ReaderT (Bool, LibPQ.Result) (EitherT Error IO) a)+ Result (ReaderT (Bool, LibPQ.Result) (ExceptT Error IO) a) deriving (Functor, Applicative, Monad) data Error =@@ -48,7 +48,7 @@ {-# INLINE run #-} run :: Result a -> (Bool, LibPQ.Result) -> IO (Either Error a) run (Result reader) env =- runEitherT (runReaderT reader env)+ runExceptT (runReaderT reader env) {-# INLINE unit #-} unit :: Result ()@@ -65,7 +65,7 @@ checkExecStatus $ \case LibPQ.CommandOk -> True _ -> False- Result $ ReaderT $ \(_, result) -> EitherT $+ Result $ ReaderT $ \(_, result) -> ExceptT $ LibPQ.cmdTuples result & fmap cmdTuplesReader where cmdTuplesReader =@@ -92,12 +92,12 @@ LibPQ.BadResponse -> serverError LibPQ.NonfatalError -> serverError LibPQ.FatalError -> serverError- _ -> Result $ lift $ EitherT $ pure $ Left $ UnexpectedResult $ "Unexpected result status: " <> (fromString $ show status)+ _ -> Result $ lift $ ExceptT $ pure $ Left $ UnexpectedResult $ "Unexpected result status: " <> (fromString $ show status) {-# INLINE serverError #-} serverError :: Result () serverError =- Result $ ReaderT $ \(_, result) -> EitherT $ do+ Result $ ReaderT $ \(_, result) -> ExceptT $ do code <- fmap (fromMaybe ($bug "No code")) $ LibPQ.resultErrorField result LibPQ.DiagSqlstate@@ -117,7 +117,7 @@ checkExecStatus $ \case LibPQ.TuplesOk -> True _ -> False- Result $ ReaderT $ \(integerDatetimes, result) -> EitherT $ do+ Result $ ReaderT $ \(integerDatetimes, result) -> ExceptT $ do maxRows <- LibPQ.ntuples result case maxRows of 0 -> return (Right Nothing)@@ -138,7 +138,7 @@ checkExecStatus $ \case LibPQ.TuplesOk -> True _ -> False- Result $ ReaderT $ \(integerDatetimes, result) -> EitherT $ do+ Result $ ReaderT $ \(integerDatetimes, result) -> ExceptT $ do maxRows <- LibPQ.ntuples result case maxRows of 1 -> do@@ -158,7 +158,7 @@ checkExecStatus $ \case LibPQ.TuplesOk -> True _ -> False- Result $ ReaderT $ \(integerDatetimes, result) -> EitherT $ do+ Result $ ReaderT $ \(integerDatetimes, result) -> ExceptT $ do maxRows <- LibPQ.ntuples result maxCols <- LibPQ.nfields result mvector <- MutableVector.unsafeNew (rowToInt maxRows)@@ -185,7 +185,7 @@ checkExecStatus $ \case LibPQ.TuplesOk -> True _ -> False- Result $ ReaderT $ \(integerDatetimes, result) -> EitherT $ {-# SCC "traversal" #-} do+ Result $ ReaderT $ \(integerDatetimes, result) -> ExceptT $ {-# SCC "traversal" #-} do maxRows <- LibPQ.ntuples result maxCols <- LibPQ.nfields result accRef <- newIORef init@@ -212,7 +212,7 @@ checkExecStatus $ \case LibPQ.TuplesOk -> True _ -> False- Result $ ReaderT $ \(integerDatetimes, result) -> EitherT $ do+ Result $ ReaderT $ \(integerDatetimes, result) -> ExceptT $ do maxRows <- LibPQ.ntuples result maxCols <- LibPQ.nfields result accRef <- newIORef init
library/Hasql/Private/Decoders/Results.hs view
@@ -19,7 +19,7 @@ newtype Results a =- Results (ReaderT (Bool, LibPQ.Connection) (EitherT Error IO) a)+ Results (ReaderT (Bool, LibPQ.Connection) (ExceptT Error IO) a) deriving (Functor, Applicative, Monad) data Error =@@ -34,12 +34,12 @@ {-# INLINE run #-} run :: Results a -> (Bool, LibPQ.Connection) -> IO (Either Error a) run (Results stack) env =- runEitherT (runReaderT stack env)+ runExceptT (runReaderT stack env) {-# INLINE clientError #-} clientError :: Results a clientError =- Results $ ReaderT $ \(_, connection) -> EitherT $+ Results $ ReaderT $ \(_, connection) -> ExceptT $ fmap (Left . ClientError) (LibPQ.errorMessage connection) -- |@@ -47,7 +47,7 @@ {-# INLINE single #-} single :: Result.Result a -> Results a single resultDec =- Results $ ReaderT $ \(integerDatetimes, connection) -> EitherT $ do+ Results $ ReaderT $ \(integerDatetimes, connection) -> ExceptT $ do resultMaybe <- LibPQ.getResult connection case resultMaybe of Just result ->@@ -60,7 +60,7 @@ {-# INLINE getResult #-} getResult :: Results LibPQ.Result getResult =- Results $ ReaderT $ \(_, connection) -> EitherT $ do+ Results $ ReaderT $ \(_, connection) -> ExceptT $ do resultMaybe <- LibPQ.getResult connection case resultMaybe of Just result -> pure (Right result)@@ -88,4 +88,4 @@ loop integerDatetimes connection <* checkErrors where checkErrors =- EitherT $ fmap (mapLeft ResultError) $ Result.run Result.unit (integerDatetimes, result)+ ExceptT $ fmap (mapLeft ResultError) $ Result.run Result.unit (integerDatetimes, result)
library/Hasql/Private/Decoders/Row.hs view
@@ -7,7 +7,7 @@ newtype Row a =- Row (ReaderT Env (EitherT Error IO) a)+ Row (ReaderT Env (ExceptT Error IO) a) deriving (Functor, Applicative, Monad) data Env =@@ -28,12 +28,12 @@ run (Row impl) (result, row, columnsAmount, integerDatetimes) = do columnRef <- newIORef 0- runEitherT (runReaderT impl (Env result row columnsAmount integerDatetimes columnRef))+ runExceptT (runReaderT impl (Env result row columnsAmount integerDatetimes columnRef)) {-# INLINE error #-} error :: Error -> Row a error x =- Row (ReaderT (const (EitherT (pure (Left x)))))+ Row (ReaderT (const (ExceptT (pure (Left x))))) -- | -- Next value, decoded using the provided value decoder.@@ -41,7 +41,7 @@ value :: Value.Value a -> Row (Maybe a) value valueDec = {-# SCC "value" #-} - Row $ ReaderT $ \(Env result row columnsAmount integerDatetimes columnRef) -> EitherT $ do+ Row $ ReaderT $ \(Env result row columnsAmount integerDatetimes columnRef) -> ExceptT $ do col <- readIORef columnRef writeIORef columnRef (succ col) if col < columnsAmount
library/Hasql/Private/IO.hs view
@@ -114,9 +114,9 @@ [Maybe (ByteString, LibPQ.Format)] -> IO (Either ResultsDecoders.Error ()) sendPreparedParametricQuery connection registry template oidList valueAndFormatList =- runEitherT $ do- key <- EitherT $ getPreparedStatementKey connection registry template oidList- EitherT $ checkedSend connection $ LibPQ.sendQueryPrepared connection key valueAndFormatList LibPQ.Binary+ runExceptT $ do+ key <- ExceptT $ getPreparedStatementKey connection registry template oidList+ ExceptT $ checkedSend connection $ LibPQ.sendQueryPrepared connection key valueAndFormatList LibPQ.Binary {-# INLINE sendUnpreparedParametricQuery #-} sendUnpreparedParametricQuery ::
library/Hasql/Private/Prelude.hs view
@@ -10,6 +10,7 @@ forMToZero_, forMFromZero_, strictCons,+ mapLeft, ) where @@ -22,9 +23,13 @@ ------------------------- import Control.Monad.IO.Class as Exports import Control.Monad.Trans.Class as Exports-import Control.Monad.Trans.Maybe as Exports hiding (liftListen, liftPass)-import Control.Monad.Trans.Reader as Exports hiding (liftCallCC, liftCatch)-import Control.Monad.Trans.State.Strict as Exports hiding (liftCallCC, liftCatch, liftListen, liftPass)+import Control.Monad.Trans.Cont as Exports hiding (shift, callCC)+import Control.Monad.Trans.Except as Exports (ExceptT(ExceptT), Except, except, runExcept, runExceptT, mapExcept, mapExceptT, withExcept, withExceptT, throwE, catchE)+import Control.Monad.Trans.Maybe as Exports+import Control.Monad.Trans.Reader as Exports (Reader, runReader, mapReader, withReader, ReaderT(ReaderT), runReaderT, mapReaderT, withReaderT)+import Control.Monad.Trans.State.Strict as Exports (State, runState, evalState, execState, mapState, withState, StateT(StateT), runStateT, evalStateT, execStateT, mapStateT, withStateT)+import Control.Monad.Trans.Writer.Strict as Exports (Writer, runWriter, execWriter, mapWriter, WriterT(..), execWriterT, mapWriterT)+import Data.Functor.Compose as Exports import Data.Functor.Identity as Exports -- mtl@@ -48,11 +53,6 @@ ------------------------- import Contravariant.Extras as Exports --- either---------------------------import Control.Monad.Trans.Either as Exports-import Data.Either.Combinators as Exports- -- semigroups ------------------------- import Data.Semigroup as Exports@@ -128,3 +128,8 @@ strictCons :: a -> [a] -> [a] strictCons !a b = let !c = a : b in c++{-# INLINE mapLeft #-}+mapLeft :: (a -> c) -> Either a b -> Either c b+mapLeft f =+ either (Left . f) Right
library/Hasql/Private/Query.hs view
@@ -34,7 +34,7 @@ -- else insert -< params -- @ newtype Query a b =- Query (Kleisli (ReaderT Connection.Connection (EitherT Decoders.Results.Error IO)) a b)+ Query (Kleisli (ReaderT Connection.Connection (ExceptT Decoders.Results.Error IO)) a b) deriving (Category, Arrow, ArrowChoice, ArrowLoop, ArrowApply) instance Functor (Query a) where@@ -54,7 +54,7 @@ statement template encoder decoder preparable = Query $ Kleisli $ \params -> ReaderT $ \(Connection.Connection pqConnectionRef integerDatetimes registry) -> - EitherT $ withMVar pqConnectionRef $ \pqConnection -> do+ ExceptT $ withMVar pqConnectionRef $ \pqConnection -> do r1 <- IO.sendParametricQuery pqConnection integerDatetimes registry template encoder preparable params r2 <- IO.getResults pqConnection integerDatetimes decoder return $ r1 *> r2
library/Hasql/Private/Session.hs view
@@ -14,14 +14,14 @@ -- | -- A batch of actions to be executed in the context of a database connection. newtype Session a =- Session (ReaderT Connection.Connection (EitherT Error IO) a)+ Session (ReaderT Connection.Connection (ExceptT Error IO) a) deriving (Functor, Applicative, Monad, MonadError Error, MonadIO) -- | -- Executes a bunch of commands on the provided connection. run :: Session a -> Connection.Connection -> IO (Either Error a) run (Session impl) connection =- runEitherT $+ runExceptT $ runReaderT impl connection -- |@@ -31,7 +31,7 @@ sql :: ByteString -> Session () sql sql = Session $ ReaderT $ \(Connection.Connection pqConnectionRef integerDatetimes registry) ->- EitherT $ fmap (mapLeft unsafeCoerce) $ withMVar pqConnectionRef $ \pqConnection -> do+ ExceptT $ fmap (mapLeft unsafeCoerce) $ withMVar pqConnectionRef $ \pqConnection -> do r1 <- IO.sendNonparametricQuery pqConnection sql r2 <- IO.getResults pqConnection integerDatetimes decoder return $ r1 *> r2
tasty/Main/Connection.hs view
@@ -9,10 +9,10 @@ with :: (HC.Connection -> IO a) -> IO (Either HC.ConnectionError a) with handler =- runEitherT $ acquire >>= \connection -> use connection <* release connection+ runExceptT $ acquire >>= \connection -> use connection <* release connection where acquire =- EitherT $ HC.acquire settings+ ExceptT $ HC.acquire settings where settings = HC.settings host port user password database
tasty/Main/DSL.hs view
@@ -26,10 +26,10 @@ session :: Session a -> IO (Either SessionError a) session session =- runEitherT $ acquire >>= \connection -> use connection <* release connection+ runExceptT $ acquire >>= \connection -> use connection <* release connection where acquire =- EitherT $ fmap (mapLeft ConnectionError) $ HC.acquire settings+ ExceptT $ fmap (mapLeft ConnectionError) $ HC.acquire settings where settings = HC.settings host port user password database@@ -40,7 +40,7 @@ password = "" database = "postgres" use connection =- EitherT $+ ExceptT $ fmap (mapLeft SessionError) $ Hasql.Session.run session connection release connection =