persistent-mysql-haskell 0.3.4.1 → 0.3.5
raw patch · 4 files changed
+25/−30 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog.md +3/−0
- Database/Persist/MySQL.hs +17/−28
- README.md +4/−1
- persistent-mysql-haskell.cabal +1/−1
ChangeLog.md view
@@ -1,3 +1,6 @@+## 0.3.5+- Updated `selectSource` implementation to stream results instead of loading everything into memory.+ ## 0.3.4.1 - Fix a haddock issue down-streamed from [#693](https://github.com/yesodweb/persistent/pull/693).
Database/Persist/MySQL.hs view
@@ -56,6 +56,7 @@ import Data.Conduit import qualified Data.ByteString.Lazy as BS+import qualified Data.Conduit as C import qualified Data.Conduit.List as CL import qualified Data.Map as Map import qualified Data.Text as T@@ -208,40 +209,28 @@ query' conn qry [] = MySQL.query_ conn qry query' conn qry ps = MySQL.query conn qry ps --- | Execute an statement that does return results. The results--- are fetched all at once and stored into memory.+-- | Execute an statement that does return results.+-- unlike @persistent-mysql@, we actually _stream_ results. withStmt' :: MonadIO m => MySQL.MySQLConn -> MySQL.Query -> [PersistValue]- -> Acquire (Source m [PersistValue])-withStmt' conn query vals = do- result <- mkAcquire createResult releaseResult- return $ fetchRows result >>= CL.sourceList+ -> Acquire (C.Source m [PersistValue])+withStmt' conn query vals+ = fetchRows <$> mkAcquire createResult releaseResult where- createResult = return $ query' conn query (map P vals)- releaseResult _ = return ()-- fetchRows result = liftIO $ do+ createResult = query' conn query (map P vals)+ releaseResult (_, is) = Streams.skipToEof is+ fetchRows (fields, is) = CL.unfoldM getVal is+ where -- Find out the type of the columns- (fields, is) <- result- -- let getters = [ maybe PersistNull (getGetter f f . Just) | f <- fields]- let getters = fmap getGetter fields- convert = use getters- where use (g:gs) (col:cols) =- let v = g col- vs = use gs cols- in v `seq` vs `seq` (v:vs)- use _ _ = []-- -- Ready to go!- let go acc = do- row <- Streams.read is- case row of- Nothing -> return (acc [])- (Just r) -> let converted = convert r- in converted `seq` go (acc . (converted:))- go id+ getters = fmap getGetter fields+ convert = zipWith (\g -> \c -> g c) getters+ getVal s = do+ v <- liftIO $ Streams.read s+ case v of+ (Just r) -> pure $ Just (convert r, s)+ _ -> pure Nothing -- | Encode a Haskell bool into a MySQLValue encodeBool :: Bool -> MySQL.MySQLValue
README.md view
@@ -20,12 +20,15 @@ - better portability and possible static compilation of an entire project that uses `persistent-mysql`. +- result streaming support means persistent [`selectSource` streams data from database](http://www.jakubkonka.com/2014/01/23/conduit-haskell.html). Effectively addressing [#657 selectSource does not stream results](https://github.com/yesodweb/persistent/issues/657). +- a newtype-d `MySQLConnectInfo` allows adding configuring _how_ persistent and the underlying driver are glued. Ex: [#679](https://github.com/yesodweb/persistent/issues/679) can be elegantly addressed in this library.+ Personal experience on replacing `mysql-simple` with `mysql-haskell` in a project: - Performance gains consistent with benchmark. -- Smoother deployment to [Amazon AMI/EC2](https://en.wikipedia.org/wiki/Amazon_Machine_Image), since `mysql` appears to have a hard dependency on the oracle version of `libmysqlclient` that does not work with the open source variant that is available by default on EC2 (and possibly on other cloud providers).+- Smoother deployment to [AWS](https://en.wikipedia.org/wiki/Amazon_Machine_Image), since `mysql` appears to have a hard dependency on the oracle version of `libmysqlclient` that does not work with the open source variant that is available by default on Amazon Linux (and possibly on other Linux distros). ### Potential issues moving from persistent-mysql to persistent-mysql-haskell
persistent-mysql-haskell.cabal view
@@ -1,5 +1,5 @@ name: persistent-mysql-haskell-version: 0.3.4.1+version: 0.3.5 license: MIT license-file: LICENSE author: Naushadh <naushadh@protonmail.com>, Felipe Lessa <felipe.lessa@gmail.com>, Michael Snoyman