Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tjheeta/mysqlex
Mysql driver for Elixir from Erlang
https://github.com/tjheeta/mysqlex
Last synced: 3 months ago
JSON representation
Mysql driver for Elixir from Erlang
- Host: GitHub
- URL: https://github.com/tjheeta/mysqlex
- Owner: tjheeta
- Created: 2015-05-31T17:25:43.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-03-03T15:32:58.000Z (almost 5 years ago)
- Last Synced: 2024-10-13T01:09:26.779Z (3 months ago)
- Language: Elixir
- Homepage:
- Size: 8.79 KB
- Stars: 8
- Watchers: 2
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - An Ecto-compatible wrapper around the mysql-otp library. (ORM and Datamapping)
- fucking-awesome-elixir - mysqlex - An Ecto-compatible wrapper around the mysql-otp library. (ORM and Datamapping)
- awesome-elixir - mysqlex - An Ecto-compatible wrapper around the mysql-otp library. (ORM and Datamapping)
README
Mysqlex
=======This is a wrapper around a newer mysql library for erlang:
https://github.com/mysql-otp
There are benchmarks for the mysql drivers:
* http://tjheeta.github.io/2015/05/31/elixir-and-erlang-mysql-drivers.html
* http://tjheeta.github.io/2015/05/30/benchmarking-elixir-postgres-mysql-ecto.html## Usage
To use add the following to your mix.exs:
~~~
def deps do
[{:mysqlex, github: "tjheeta/mysqlex" } ]
end
~~~Profit:
~~~
iex(8)> {:ok, pid} = Mysqlex.Connection.start_link(username: "test", database: "test", password: "test", hostname: "10.0.3.82")
{:ok, #PID<0.1420.0>}
iex(9)> Mysqlex.Connection.query(pid, "CREATE TABLE posts (id serial, title text)")
{:ok,
%Mysqlex.Result{columns: [], command: :create, last_insert_id: 0, num_rows: 0,
rows: []}}
iex(10)> Mysqlex.Connection.query(pid, "CREATE TABLE posts (id serial, title text)")
{:error,
%Mysqlex.Error{message: "1050 - Table 'posts' already exists", mysqlex: nil}}
iex(11)> Mysqlex.Connection.query(pid, "INSERT INTO posts (title) VALUES ('my title')")
{:ok,
%Mysqlex.Result{columns: [], command: :insert, last_insert_id: 1, num_rows: 1,
rows: []}}
iex(12)> Mysqlex.Connection.query(pid, "SELECT title FROM posts", [])
{:ok,
%Mysqlex.Result{columns: ["title"], command: :select, last_insert_id: nil,
num_rows: 1, rows: [{"my title"}]}}
iex(13)> Mysqlex.Connection.query(pid, "SELECT id FROM posts WHERE title like ?", ["%my%"])
{:ok,
%Mysqlex.Result{columns: ["id"], command: :select, last_insert_id: nil,
num_rows: 1, rows: [{1}]}}~~~
To use with ecto, you'll have to patch it for now:
https://gist.github.com/tjheeta/800deab2b9e7b2b9651b