persistent-mysql-pure: A pure haskell backend for the persistent library using MySQL database server.

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Warnings:

This package contains a backend for persistent using the MySQL database server. Internally it uses the mysql-pure package in order to access the database. See README.md for more.

This package supports only MySQL 5.1 and above. However, it has been tested only on MySQL 5.5. Only the InnoDB storage engine is officially supported.

Known problems:


[Skip to Readme]

Properties

Versions 1.0.0, 1.0.0, 1.0.1, 1.0.2
Change log ChangeLog.md
Dependencies aeson (>=1.0 && <2.3), base (>=4.9 && <4.19), bytestring (>=0.10.8 && <0.13), conduit (>=1.2.12 && <1.4), containers (>=0.5 && <0.7), io-streams (>=1.2 && <2.0), monad-logger (>=0.3.0 && <0.4), mysql-pure (>=1.0 && <2.0), network (>=2.3 && <4.0), persistent (>=2.10.0 && <3), persistent-mysql-pure, resource-pool (<0.5), resourcet (>=1.1 && <1.4), text (>=1.2 && <2.1), time (>=1.5.0 && <1.13), tls (>=1.3.5 && <1.6), transformers (>=0.5 && <0.7), unliftio-core (<0.3) [details]
License MIT
Author Naushadh <naushadh@protonmail.com>, Felipe Lessa <felipe.lessa@gmail.com>, Michael Snoyman
Maintainer Jappie <hi@jappie.me>
Category Database, Yesod
Home page http://www.yesodweb.com/book/persistent
Bug tracker https://github.com/jappeace/persistent-mysql-pure/issues
Source repo head: git clone git://github.com/jappeace/persistent-mysql-pure.git
Uploaded by Jappie at 2023-08-13T04:26:49Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for persistent-mysql-pure-1.0.0

[back to package description]

persistent-mysql-pure

hackage version

This is a fork of persistent-mysql-haskell. Using the latest branch from chordify.

A pure haskell backend for persistent using the MySQL database server. Internally it uses the mysql-pure 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:

Personal experience on replacing mysql-simple with mysql-pure in a project:

Potential issues moving from persistent-mysql to persistent-mysql-pure

ConnectInfo and defaultConnectInfo are not the same between mysql and mysql-pure, therefore this package is not a 100% drop in replacement for persistent-mysql from the connection configuration perspective.

Aside from connection configuration, persistent-mysql-pure is functionally on par with persistent-mysql (as of writing this). This can be seen by comparing persistent-test between this fork and upstream.

Yesod

In order to use persistent-mysql-pure with yesod you have to modify Settings.hs:

- import Database.Persist.MySQL     (MySQLConf (..))
+ import Database.Persist.MySQL     (MySQLConf, mkMySQLConf, myConnInfo, myPoolSize, setMySQLConnectInfoCharset)
- import qualified Database.MySQL.Base as MySQL
-         -- 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:

- import qualified Database.MySQL.Base as MySQL
  import Network.Wai.Handler.Warp             (Settings, defaultSettings,
                                               defaultShouldDisplayException,
                                               runSettings, setHost,
-                                              setFork, setOnOpen, setOnClose,
+                                              setFork,
                                               setOnException, setPort, getPort)
-     -- See http://www.yesodweb.com/blog/2016/11/use-mysql-safely-in-yesod
-     MySQL.initLibrary
-     $ 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):

- import Database.Persist.Sql (ConnectionPool, runSqlPool)
+ import Database.Persist.Sql (ConnectionPool, rawExecute, runSqlPool)
-         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 supports X but persistent-mysql-pure API doesn't. Why?

Does persistent-mysql-pure ship with tests?