@hackage persistent-mysql-haskell0.3.0.0
A pure haskell backend for the persistent library using MySQL database server.
Categories
License
MIT
Maintainer
Naushadh <naushadh@protonmail.com>
Links
Versions
Installation
Dependencies (17)
- aeson >=0.6.2
- base >=4.6 && <5
- bytestring >=0.9
- conduit >=0.5.3
- containers >=0.2
- io-streams >=1.2 && <2.0 Show all…
Dependents (0)
persistent-mysql-haskell
A pure haskell backend for persistent using the MySQL database server. Internally it uses the mysql-haskell driver in order to access the database.
See example/Main.hs for how this MySQL backend can be used with Persistent.
Motivation
persistent-mysql uses mysql (via mysql-simple) as the database driver. mysql is a haskell FFI wrapper for mysqlclient written in C.
Reasons to use a pure haskell driver:
-
mysqlhas concurrency issues as noted by @feuerbach. -
mysql-haskell, a pure haskell driver by @winterland1989, outperforms
mysql-simplein benchmarks (see hackage or project repo). -
better portability and possible static compilation of an entire project that uses
persistent-mysql.
Personal experience on replacing mysql-simple with mysql-haskell in a project:
-
Performance gains consistent with benchmark.
-
Smoother deployment to Amazon AMI/EC2, since
mysqlappears to have a hard dependency on the oracle version oflibmysqlclientthat does not work with the open source variant that is available by default on EC2 (and possibly on other cloud providers).
Potential issues moving from persistent-mysql to persistent-mysql-haskell
ConnectInfo and defaultConnectInfo are not the same between mysql and mysql-haskell, therefore this package is not a 100% drop in replacement for persistent-mysql from the connection configuration perspective.
-
mysql-haskelldoes not allow provide an API for the entirety of mysqlclient options. Therefore neither can this package. -
Given the inevitable incompatibility with
persistent-mysql, and in the interest of providing a forward-compatible API,ConnectInfointernals anddefaultConnectInfohave been deprecated. However the similar utility can be achieved like so:import Database.Persist.MySQL connectInfo :: MySQLConnectInfo - connectInfo = defaultConnectInfo - { connectHost = "localhost" - , connectUser = "test" - , connectPassword = "test" - , connectDatabase = "test" - } + connectInfo = mkMySQLConnectInfo "localhost" "test" "test" "test" connectInfoNewPort :: MySQLConnectInfo - connectInfoNewPort = connectInfo { connectPort = 3307 } + connectInfoNewPort = setMySQLConnectInfoPort 3307 connectInfo connectInfoNewCharSet :: MySQLConnectInfo - connectInfoNewCharSet = connectInfo { connectOptions = [CharsetName "utf8"] } + connectInfoNewCharSet = setMySQLConnectInfoCharset 33 connectInfo
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.
FAQs
Why isn't this part of the main/upstream persistent repo?
- TLDR: Upstream wants to gauge community interest before absorbing this backend into the main repo.
- Long version: See issue yesodweb/persistent/issues/659.
persistent-mysql supports X but persistent-mysql-haskell API doesn't. Why?
-
Internals (getters/setters) of MySQLConnectInfo and
defaultConnectInfoare intentionally masked for forward compatibility. -
For all others, feel free to open an issue and/or submit a PR.
Does persistent-mysql-haskell ship with tests?
-
It does! :)
persistent-testis fully re-used with an additional flag to specifically test persistent-mysql-haskell.stack test persistent-test --flag persistent-test:mysql_haskell