Last active
August 29, 2015 14:16
-
-
Save jamesbee/2be415394aff81dc8103 to your computer and use it in GitHub Desktop.
Elixir connect to mysql example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Conn do | |
def test do | |
stat = "select * from users limit 10;" | |
:emysql.add_pool :demo_pool, [ | |
size: 1, | |
user: 'root', | |
password: 'root', | |
database: 'demo', | |
encoding: :utf8 # you will need this | |
] | |
res = :emysql.execute :demo_pool, stat | |
rows = :emysql.as_proplist res | |
# from keyword list to elixir map | |
Enum.map rows, &Enum.into(&1, %{}) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SomeProject.Mixfile do | |
use Mix.Project | |
## | |
# bla, bla, bla | |
## | |
# Add crypto, emysql to application start link. | |
def application do | |
[applications: [:crypto, :emysql]] | |
end | |
# Add emysql dependencies | |
defp deps do | |
[{:emysql, github: "Eonblast/Emysql", ref: "HEAD"}] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment