packages feed

persistent-mysql-haskell 0.4.0 → 0.4.1

raw patch · 4 files changed

+81/−2 lines, 4 files

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.4.1++- Fix [#2](https://github.com/naushadh/persistent/issues/2): Better compatibility with `yesod` scaffold.+ ## 0.4.0  - Port [#770](https://github.com/yesodweb/persistent/pull/770) from `persistent-mysql`: Performance enhancements for bulk writes.
Database/Persist/MySQL.hs view
@@ -39,6 +39,9 @@   , MySQLTLS.TrustedCAStore(..)   , MySQLTLS.makeClientParams   , MySQLTLS.makeClientParams'+  -- * persistent-mysql compatibility+  , myConnInfo+  , myPoolSize ) where  import Control.Arrow@@ -917,9 +920,16 @@     Int     deriving Show +-- | Extract connection configs from 'MySQLConf'+-- @since 0.4.1 myConnInfo :: MySQLConf -> MySQLConnectInfo myConnInfo (MySQLConf c _) = c +-- | Extract connection pool size from 'MySQLConf'+-- @since 0.4.1+myPoolSize :: MySQLConf -> Int+myPoolSize (MySQLConf _ p) = p+ setMyConnInfo :: MySQLConnectInfo -> MySQLConf -> MySQLConf setMyConnInfo c (MySQLConf _ p) = MySQLConf c p @@ -988,7 +998,7 @@         pool     <- o .: "poolsize"         let ci = MySQL.defaultConnectInfo                    { MySQL.ciHost     = host-                   , MySQL.ciPort     = read port+                   , MySQL.ciPort     = fromIntegral (port :: Word)                    , MySQL.ciUser     = BSC.pack user                    , MySQL.ciPassword = BSC.pack password                    , MySQL.ciDatabase = BSC.pack database
README.md view
@@ -77,6 +77,71 @@  Aside from connection configuration, persistent-mysql-haskell is functionally on par with persistent-mysql (as of writing this). This can be seen by [comparing persistent-test between this fork and upstream](https://github.com/yesodweb/persistent/compare/master...naushadh:persistent-mysql-haskell#diff-028f5df7b2b9c5c8b0fa670fc8c69bff). +#### Yesod++In order to use `persistent-mysql-haskell` with `yesod` you have to modify `Settings.hs`:++  ```diff+  - import Database.Persist.MySQL     (MySQLConf (..))+  + import Database.Persist.MySQL     (MySQLConf, mkMySQLConf, myConnInfo, myPoolSize, setMySQLConnectInfoCharset)+  ```++  ```diff+  - import qualified Database.MySQL.Base as MySQL+  ```++  ```diff+  -         -- This code enables MySQL's strict mode, without which MySQL will truncate data.+  -         -- See https://github.com/yesodweb/persistent/wiki/Database-Configuration#strict-mode for details+  -         -- If you choose to keep strict mode enabled, it's recommended that you enable it in your my.cnf file so that it's also enabled for your MySQL console sessions.+  -         -- (If you enable it in your my.cnf file, you can delete this code).+  -         let appDatabaseConf = fromYamlAppDatabaseConf { myConnInfo = (myConnInfo fromYamlAppDatabaseConf) {+  -                 MySQL.connectOptions =+  -                   ( MySQL.connectOptions (myConnInfo fromYamlAppDatabaseConf)) ++ [MySQL.InitCommand "SET SESSION sql_mode = 'STRICT_ALL_TABLES';\0"]+  -               }+  -             }+  ```++And in `Application.hs`:++  ```diff+  - import qualified Database.MySQL.Base as MySQL+  ```++  ```diff+    import Network.Wai.Handler.Warp             (Settings, defaultSettings,+                                                 defaultShouldDisplayException,+                                                 runSettings, setHost,+  -                                              setFork, setOnOpen, setOnClose,+  +                                              setFork,+                                                 setOnException, setPort, getPort)+  ```++  ```diff+  -     -- See http://www.yesodweb.com/blog/2016/11/use-mysql-safely-in-yesod+  -     MySQL.initLibrary+  ```++  ```diff+  -     $ setOnOpen (const $ MySQL.initThread >> return True)+  -     $ setOnClose (const MySQL.endThread)+  ```++Optionally you may enable the MYSQL strict mode (in each transaction)+by modifying `Foundation.hs` (or editing the `my.cnf` server configuration):++  ```diff+  - import Database.Persist.Sql (ConnectionPool, runSqlPool)+  + import Database.Persist.Sql (ConnectionPool, rawExecute, runSqlPool)+  ```++  ```diff+  -         runSqlPool action $ appConnPool master+  +         runSqlPool+  +           (rawExecute "SET SESSION sql_mode = 'STRICT_ALL_TABLES'" [] >> action)+  +           (appConnPool master)+  ```+ ### FAQs  #### Why isn't this part of the main/upstream persistent repo?
persistent-mysql-haskell.cabal view
@@ -1,5 +1,5 @@ name:            persistent-mysql-haskell-version:         0.4.0+version:         0.4.1 license:         MIT license-file:    LICENSE author:          Naushadh <naushadh@protonmail.com>, Felipe Lessa <felipe.lessa@gmail.com>, Michael Snoyman