-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from altenwald/feature/elixir
Support for Elixir
- Loading branch information
Showing
11 changed files
with
291 additions
and
16 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
defmodule DBI do | ||
use Application | ||
|
||
# wrap from dbi_app.erl | ||
def start(type, args), do: :dbi_app.start(type, args) | ||
def stop(modules), do: :dbi_app.stop(modules) | ||
|
||
# wrap from dbi.erl | ||
def start(), do: :dbi.start() | ||
def do_query(pool, query), do: :dbi.do_query(pool, query) | ||
def do_query(pool, query, args), do: :dbi.do_query(pool, query, args) | ||
def connect(type, host, port, user, pass, database, poolname) do | ||
:dbi.connect(type, host, port, user, pass, database, poolname) | ||
end | ||
def connect(type, host, port, user, pass, db, poolname, poolsize, extra) do | ||
:dbi.connect(type, host, port, user, pass, db, poolname, poolsize, extra) | ||
end | ||
|
||
defmodule Cache do | ||
def do_query(ref, query), do: :dbi_cache.do_query(ref, query) | ||
def do_query(ref, query, args), do: :dbi_cache.do_query(ref, query, args) | ||
def do_query(ref, query, args, ttl) do | ||
:dbi_cache.do_query(ref, query, args, ttl) | ||
end | ||
end | ||
|
||
defmodule Delayed do | ||
def start_link(ref, conn), do: :dbi_delayed.start_link(ref, conn) | ||
def do_query(ref, query, args), do: :dbi_delayed.do_query(ref, query, args) | ||
def do_query(ref, query), do: :dbi_delayed.do_query(ref, query) | ||
def stats(ref), do: :dbi_delayed.stats(ref) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
defmodule DBI.Mixfile do | ||
use Mix.Project | ||
|
||
def project do | ||
[app: :dbi, | ||
version: get_version(), | ||
name: "DBI", | ||
description: "DataBase Interface for Erlang", | ||
package: package(), | ||
source_url: "https://github.com/altenwald/dbi", | ||
elixir: "~> 1.3", | ||
compilers: Mix.compilers, | ||
build_embedded: Mix.env == :prod, | ||
start_permanent: Mix.env == :prod, | ||
deps: deps()] | ||
end | ||
|
||
def application do | ||
env = if Mix.env == :test do | ||
[testdb1: [type: :sqlite, | ||
database: ':memory:'], | ||
testdb2: [type: :sqlite, | ||
database: ':memory:', | ||
cache: 3], | ||
testdb3: [type: :sqlite, | ||
database: ':memory:', | ||
delayed: :mydelayed] | ||
] | ||
else | ||
[] | ||
end | ||
[applications: [:crypto, :public_key, :asn1, :ssl], | ||
mod: {DBI, []}, | ||
env: env] | ||
end | ||
|
||
defp deps do | ||
[{:epgsql, "~> 3.4.0"}, | ||
{:p1_mysql, "~> 1.0.4"}, | ||
{:esqlite, "~> 0.2.3"}, | ||
{:cache, "~> 2.2.0"}, | ||
{:poolboy, "~> 1.5.1"}] | ||
end | ||
|
||
defp package do | ||
[files: ["lib", "mix.exs", "README*", "LICENSE*"], | ||
maintainers: ["Manuel Rubio"], | ||
licenses: ["LGPL 2.1"], | ||
links: %{"GitHub" => "https://github.com/altenwald/dbi"}] | ||
end | ||
|
||
defp get_version do | ||
retrieve_version_from_git() | ||
|> String.split("-") | ||
|> case do | ||
[tag] -> tag | ||
[tag, _num_commits, commit] -> "#{tag}-#{commit}" | ||
end | ||
end | ||
|
||
defp retrieve_version_from_git do | ||
System.cmd("git", ["describe", "--always", "--tags"]) | ||
|> Tuple.to_list | ||
|> List.first | ||
|> String.strip | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%{"cache": {:hex, :cache, "2.2.0", "3c11dbf4cd8fcd5787c95a5fb2a04038e3729cfca0386016eea8c953ab48a5ab", [:rebar3], [], "hexpm"}, | ||
"epgsql": {:hex, :epgsql, "3.4.0", "39d473b83d74329a88f8fb1f99ad24c7a2329fd753957c488808cb7c0fc8164e", [:rebar3], [], "hexpm"}, | ||
"esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, | ||
"p1_mysql": {:hex, :p1_mysql, "1.0.4", "7b9d7957a9d031813a0e6bcea5a7f5e91b54db805a92709a445cf75cf934bc1d", [:rebar3], [], "hexpm"}, | ||
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"}} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-module(dbi_utils). | ||
-module(dbi_query). | ||
-author('[email protected]'). | ||
|
||
-export([ | ||
|
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
Oops, something went wrong.