diff --git a/.travis.yml b/.travis.yml index 1961a39..d478707 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,20 @@ language: elixir os: - linux - #- osx + - osx elixir: - 1.4.2 - 1.4 before_install: env: - MYSQLEX_POOL_USER=world MYSQLEX_POOL_PASSWORD=world MYSQLEX_POOL_HOST=127.0.0.1 MYSQLEX_POOL_PORT=3306 MYSQLEX_POOL_DATABASE=world MYSQLEX_POOL_SIZE=10 MYSQLEX_POOL_OVERFLOW=1 + - MYSQLEX_POOL_USER=other MYSQLEX_POOL_PASSWORD=supersecret MYSQLEX_POOL_HOST=localhost MYSQLEX_POOL_PORT=3306 MYSQLEX_POOL_DATABASE=world MYSQLEX_POOL_SIZE=100 MYSQLEX_POOL_OVERFLOW=5 before_script: - mysql < _dev/world.sql - mysql -u root -e "CREATE USER 'world'@'127.0.0.1' IDENTIFIED BY 'world';" - mysql -u root -e "GRANT CREATE, INSERT, SELECT, DELETE, UPDATE ON world.* TO 'world'@'127.0.0.1';" + - mysql -u root -e "CREATE USER 'other'@'localhost' IDENTIFIED BY 'supersecret';" + - mysql -u root -e "GRANT CREATE, INSERT, SELECT, DELETE, UPDATE ON other.* TO 'world'@'localhost';" script: - MIX_ENV=test mix test --trace after_success: diff --git a/Makefile b/Makefile index 1010c9d..1dde688 100644 --- a/Makefile +++ b/Makefile @@ -12,3 +12,7 @@ info: t: test test: info MIX_ENV=test mix test --trace $(TESTARG) + +b: bench +bench: info + MIX_ENV=test mix bench -d 5 diff --git a/README.md b/README.md index e326700..5a7d5fe 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,7 @@ A warpper for mysqlex to add connection pooling with poolboy ## Installation -If [available in Hex](https://hex.pm/docs/publish), the package can be installed -by adding `mysqlex_pool` to your list of dependencies in `mix.exs`: +1. Add `mysqlex_pool` to your list of dependencies in `mix.exs`: ```elixir def deps do @@ -22,12 +21,106 @@ def deps do end ``` -## TODOs +2. Ensure `mysqlex_pool` is started before your application: -- connection config ;-) -- docs +```elixir +def application do + [applications: [:mysqlex_pool]] +end +``` + +## Usage + +### `MysqlexPool.query/1` + +run a simple mysql query - [`query/1`](https://hexdocs.pm/mysqlex_pool/MysqlexPool.html#query/1) + +**`{ :ok, %Mysqlex.Result{...} } = MysqlexPool.query( "SELECT * FROM test" )`** + +**Example:** + +```elixir +{ :ok, %Mysqlex.Result{columns: ["ID", "Name"], command: :select, last_insert_id: nil, num_rows: 1, rows: [{1, "Kabul"}] } } = MysqlexPool.query( "SELECT ID, Name FROM `city` WHERE id = 1" ) +``` + +### `MysqlexPool.query/2` + +run a mysql query with param substitution - [`query/2`](https://hexdocs.pm/mysqlex_pool/MysqlexPool.html#query/2) + +**`{ :ok, %Mysqlex.Result{...} } = MysqlexPool.query( "SELECT * FROM test WHERE id = ?", [ 1337 ] )`** + +**Example:** + +```elixir +{ :ok, %Mysqlex.Result{columns: ["ID", "Name"], command: :select, last_insert_id: nil, num_rows: 1, rows: [{1, "Kabul"}] } } = MysqlexPool.query( "SELECT ID, Name FROM `city` WHERE id = ?", [ 1 ] ) +``` + +## Config + +You can set the configuration within your `config.exs` or just use the environment vars. + +- **`username`** *`Binary` default: `root`*: mysql user name. *env-var: `MYSQLEX_POOL_USER`* +- **`password`** *`Binary` default: `root`*: mysql password. *env-var: `MYSQLEX_POOL_PASSWORD`* +- **`hostname`** *`Binary` default: `127.0.0.1`*: mysql host. *env-var: `MYSQLEX_POOL_HOST`* +- **`port`** *`Integer` default: `3306`*: mysql port. *env-var: `MYSQLEX_POOL_PORT`* +- **`database`** *`Binary` default: `test`*: mysql datebase. *env-var: `MYSQLEX_POOL_DATABASE`* +- **`pool_size`** *`Integer` default: `10`*: mysqlex/poolboy pool size. *env-var: `MYSQLEX_POOL_SIZE`* +- **`pool_overflow`** *`Integer` default: `1`*: mysqlex/poolboy pool overflow. *env-var: `MYSQLEX_POOL_OVERFLOW`* +- **`charset`** *`Binary` default: `utf8`*: mysql charset. *env-var: `MYSQLEX_POOL_CHARSET`* + +## Development & Benchmarks + +All examples and tests are based on the example db `world`. +You can find a copy [here](https://raw.githubusercontent.com/mpneuried/mysqlex_pool/master/_dev/world.sql) or use the [official source](https://dev.mysql.com/doc/index-other.html) and download the `world database`. + +### Development + +To run the tests just call: +**`make test` or `make t`.** + +In this case it'll use the environment in `test.env`. +To use your own just copy it and use `make test=my_custom_test.env test` + +### Benchmarks + +To run the benchmaks just call: +**`make bench` or `make b`.** + +In this case it'll use the environment in `test.env`. +To use your own just copy it and use `make test=my_custom_test.env test` + + +## Release History + +|Version|Date|Description| +|:--:|:--:|:--| +|0.2.0|2017-03-17|added configuration, added docs, fixed travis and appveyor ci configs.| +|0.1.0|2017-03-16|initial wip version| + +## Infos Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) and published on [HexDocs](https://hexdocs.pm). Once published, the docs can be found at [https://hexdocs.pm/mysqlex_pool](https://hexdocs.pm/mysqlex_pool). +## Other projects + +|Name|Type|Description| +|:--|:--| +|[**ex-redis-sessions**](https://github.com/mpneuried/ex-redis-sessions)|Elixir|An advanced session store for Elixir and NodeJS based on Redis | +|[**mpneuried/docker_distillery**](https://hub.docker.com/r/mpneuried/docker_distillery/)|Docker Image|Create a docker container to be able to build elixir releases via distillery on different os's.| +|[**mpneuried/elixir-alpine**](https://hub.docker.com/r/mpneuried/elixir-alpine/)|Docker Image|A minimal docker container to run elixir| +|[**redis-sessions**](https://github.com/smrchy/redis-sessions)|Node.JS|An advanced session store for NodeJS and Redis| +|[**node-cache**](https://github.com/mpneuried/nodecache)|Node.JS|Simple and fast NodeJS internal caching. Node internal in memory cache like memcached.| +|[**rsmq**](https://github.com/smrchy/rsmq)|Node.JS|A really simple message queue based on redis| +|[**obj-schema**](https://github.com/mpneuried/obj-schema)|Node.JS|Simple module to validate an object by a predefined schema| + +## The MIT License (MIT) + +Copyright © 2017 M. Peter, http://www.tcs.de + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/appveyor.yml b/appveyor.yml index be794f4..6ffcd08 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -25,12 +25,17 @@ environment: MYSQLEX_POOL_SIZE: 10 MYSQLEX_POOL_OVERFLOW: 1 MIX_ENV: test + + MYSQL_PATH: C:\Program Files\MySQL\MySQL Server 5.7 + MYSQL_HOST: localhost + MYSQL_USER: root + MYSQL_PASSWORD: Password12! # configurate mysql before_test: - - SET PATH=C:\Program Files\MySQL\MySQL Server 5.7\bin;%PATH% - - mysql -e --user=root "CREATE USER 'world'@'127.0.0.1' IDENTIFIED BY 'world'" - - mysql -e --user=root "GRANT CREATE, INSERT, SELECT, DELETE, UPDATE ON world.* TO 'world'@'127.0.0.1';" + - SET PATH=%MYSQL_PATH%\bin;%PATH% + - mysqladmin --host=%MYSQL_HOST% --user=%MYSQL_USER% --password=%MYSQL_PASSWORD% "CREATE USER 'world'@'127.0.0.1' IDENTIFIED BY 'world'" + - mysqladmin --host=%MYSQL_HOST% --user=%MYSQL_USER% --password=%MYSQL_PASSWORD% "GRANT CREATE, INSERT, SELECT, DELETE, UPDATE ON world.* TO 'world'@'127.0.0.1';" services: - mysql diff --git a/mix.exs b/mix.exs index df8bc69..611269a 100644 --- a/mix.exs +++ b/mix.exs @@ -1,12 +1,17 @@ defmodule MysqlexPool.Mixfile do + @moduledoc """ + A warpper for mysqlex to add connection pooling with poolboy + """ use Mix.Project defp package do [ - files: ["lib", "mix.exs", "README.md", "LICENSE"], - maintainers: ["M. Peter"], - licenses: ["MIT"], - links: %{"GitHub" => "https://github.com/mpneuried/mysqlex_pool"} + files: [ "lib", "mix.exs", "README.md", "LICENSE" ], + maintainers: [ "M. Peter" ], + licenses: [ "MIT" ], + links: %{ + "GitHub" => "https://github.com/mpneuried/mysqlex_pool" + } ] end @@ -19,15 +24,15 @@ defmodule MysqlexPool.Mixfile do def project do [ app: :mysqlex_pool, - version: "0.1.0", + version: "0.2.0", elixir: "~> 1.4", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, - deps: deps(), - package: package(), - description: description(), - docs: [ extras: ["README.md"], main: "readme"], - test_coverage: [tool: ExCoveralls] + deps: deps( ), + package: package( ), + description: description( ), + docs: [ extras: [ "README.md" ], main: "readme" ], + test_coverage: [ tool: ExCoveralls ] ] end @@ -36,8 +41,10 @@ defmodule MysqlexPool.Mixfile do # Type "mix help compile.app" for more information def application do # Specify extra applications you'll use from Erlang/Elixir - [extra_applications: [:logger], - mod: {MysqlexPool, []}] + [ + extra_applications: [ :logger ], + mod: { MysqlexPool, [ ] } + ] end # Dependencies can be Hex packages: @@ -54,11 +61,11 @@ defmodule MysqlexPool.Mixfile do { :poolboy, "~> 1.5" }, { :mysqlex, "~> 0.0.1" }, { :benchfella, "~> 0.3.4", only: [ :dev, :test ] }, - { :dialyze, "~> 0.2", only: :dev}, - { :earmark, ">= 0.0.0", only: [:docs, :dev]}, - { :ex_doc, ">= 0.0.0", only: [:docs, :dev]}, - { :credo, "~> 0.5", only: [:dev, :test]}, - { :excoveralls, "~> 0.5", only: [:dev, :test]} + { :dialyze, "~> 0.2", only: :dev }, + { :earmark, ">= 0.0.0", only: [ :docs, :dev ] }, + { :ex_doc, ">= 0.0.0", only: [ :docs, :dev ] }, + { :credo, "~> 0.5", only: [ :dev, :test ] }, + { :excoveralls, "~> 0.5", only: [ :dev, :test ] } ] end -end \ No newline at end of file +end