mysql-haskell: pure haskell MySQL driver

[ bsd3, database, library ] [ Propose Tags ]
This version is deprecated.
Versions [RSS] 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.4.0.0, 0.4.1.0, 0.5.0.0, 0.5.1.0, 0.6.0.0, 0.7.0.0, 0.7.1.0, 0.8.0.0, 0.8.1.0, 0.8.2.0, 0.8.3.0, 0.8.4.0, 0.8.4.1, 0.8.4.2, 0.8.4.3, 1.1.0, 1.1.2, 1.1.3, 1.1.4 (info)
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), binary (>=0.8.4), blaze-textual (>=0.2 && <0.3), bytestring (>=0.10.2.0), bytestring-lexing (>=0.5 && <0.6), cryptonite (<1), io-streams (>=1.2 && <2.0), memory (>=0.8), monad-loops (>=0.4 && <0.5), network (>=2.3 && <3.0), scientific (>=0.3 && <0.4), tcp-streams (>=0.3 && <0.4), text (>=1.1 && <1.3), time (>=1.5.0), tls (>=1.3.5 && <1.4), transformers (>=0.3 && <0.6), wire-streams (>=0.0.2 && <0.1), word24 (>=1 && <2) [details]
License BSD-3-Clause
Copyright (c) 2016 Winterland
Author winterland1989
Maintainer winterland1989@gmail.com
Category Database
Home page https://github.com/winterland1989/mysql-haskell
Bug tracker https://github.com/winterland1989/mysql-haskell/issues
Source repo head: git clone git://github.com/winterland1989/mysql-haskell.git
Uploaded by winterland at 2016-08-16T00:38:13Z
Distributions LTSHaskell:1.1.4, Stackage:1.1.4
Reverse Dependencies 8 direct, 1 indirect [details]
Downloads 11421 total (89 in the last 30 days)
Rating 2.5 (votes: 3) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for mysql-haskell-0.1.0.0

[back to package description]

mysql-haskell

Build Status

mysql-haskell is a MySQL driver written entirely in haskell by @winterland1989 at infrastructure department of Didi group, it's going to be used in projects aiming at replacing old java based MySQL middlewares.

This project is still in experimental stage and lack of produciton tests, use on your own risk, any form of contributions are welcomed!

Is it fast?

In short, it's about 2 times slower than pure c/c++, but 5 times faster than old FFI bindings(mysql by Bryan O'Sullivan).

Above figures showed the time to perform a "select * from employees" from a sample table.

Motivation

While MySQL may not be the most advanced sql database, it's widely used among China companies, including but not limited to Baidu, Alibaba, Tecent etc., but haskell's MySQL support is not ideal, we only have a very basic MySQL binding written by Bryan O'Sullivan, and some higher level wrapper built on it, which have some problems:

  • lack of prepared statment and binary protocol support.

  • limited concurrency due to FFI.

  • no replication protocol support.

mysql-haskell is intended to solve these problems, and provide foundation for higher level libraries such as groundhog and persistent, so that accessing MySQL is both fast and easy in haskell.

Build Test Benchmark

Just use the old way:

git clone https://github.com/winterland1989/mysql-haskell.git
cd mysql-haskell
cabal install --only-dependencies
cabal build

Running tests require a local MySQL server, a user testMySQLHaskell and a database testMySQLHaskell, you can do it use following script:

mysql -u root -e "CREATE DATABASE IF NOT EXISTS testMySQLHaskell;"
mysql -u root -e "CREATE USER 'testMySQLHaskell'@'localhost' IDENTIFIED BY ''"
mysql -u root -e "GRANT ALL PRIVILEGES ON testMySQLHaskell.* TO 'testMySQLHaskell'@'localhost'"
mysql -u root -e "FLUSH PRIVILEGES"

You should enable binlog by adding log_bin = filename to my.cnf or add --log-bin=filename to the server, and grant replication access to testMySQLHaskell with:

mysql -u root -e "GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'testMySQLHaskell'@'localhost';"

And you should set binlog to row by adding binlog_format = ROW to my.cnf.

New features in MySQL 5.7 are tested seperately, you can run them by setting environment varible MYSQLVER=5.7, travis is keeping an eye on following combinations:

  • CABALVER=1.18 GHCVER=7.8.4 MYSQLVER=5.5
  • CABALVER=1.22 GHCVER=7.10.2 MYSQLVER=5.5
  • CABALVER=1.24 GHCVER=8.0.1 MYSQLVER=5.5
  • CABALVER=1.24 GHCVER=8.0.1 MYSQLVER=5.6
  • CABALVER=1.24 GHCVER=8.0.1 MYSQLVER=5.7

Please reference .travis.yml if you have problems with setting up test environment.

Enter benchmark directory and run ./bench.sh to benchmark 1) c++ version 2) mysql-haskell 3) FFI version mysql, you may need to modify bench.sh(change the include path) to get c++ version compiled.

Guide

Run cabal haddock and you will get pretty decent document.

Reference

MySQL official site provided intensive document, but without following project, mysql-haskell may not be written at all:

License

Copyright (c) 2016, winterland1989

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the following
  disclaimer in the documentation and/or other materials provided
  with the distribution.

* Neither the name of winterland1989 nor the names of other
  contributors may be used to endorse or promote products derived
  from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.