Add support for Ecto 2.0
This commit is contained in:
parent
6709672540
commit
d631c62867
|
|
@ -10,7 +10,7 @@ defmodule ISN do
|
|||
|
||||
Add this module as an extension when establishing your Postgrex connection:
|
||||
|
||||
Postgrex.Connection.start_link(
|
||||
Postgrex.start_link(
|
||||
database: "isn_test",
|
||||
extensions: [{ISN, {}}])
|
||||
|
||||
|
|
|
|||
4
mix.exs
4
mix.exs
|
|
@ -1,7 +1,7 @@
|
|||
defmodule ISN.Mixfile do
|
||||
use Mix.Project
|
||||
|
||||
@version "1.0.0"
|
||||
@version "1.0.1"
|
||||
|
||||
def project do
|
||||
[app: :isn,
|
||||
|
|
@ -42,7 +42,7 @@ defmodule ISN.Mixfile do
|
|||
|
||||
defp deps do
|
||||
[{:postgrex, ">= 0.9.1"},
|
||||
{:ecto, "~> 1.0"},
|
||||
{:ecto, ">= 1.0.0"},
|
||||
{:credo, "~> 0.1", only: :dev},
|
||||
{:ex_doc, "~> 0.10", only: :dev}]
|
||||
end
|
||||
|
|
|
|||
19
mix.lock
19
mix.lock
|
|
@ -1,10 +1,11 @@
|
|||
%{"bunt": {:hex, :bunt, "0.1.4"},
|
||||
"connection": {:hex, :connection, "1.0.2"},
|
||||
"credo": {:hex, :credo, "0.2.5"},
|
||||
"decimal": {:hex, :decimal, "1.1.1"},
|
||||
"earmark": {:hex, :earmark, "0.2.0"},
|
||||
"ecto": {:hex, :ecto, "1.1.1"},
|
||||
%{"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []},
|
||||
"connection": {:hex, :connection, "1.0.3", "3145f7416be3df248a4935f24e3221dc467c1e3a158d62015b35bd54da365786", [:mix], []},
|
||||
"credo": {:hex, :credo, "0.4.5", "5c5daaf50a2a96068c0f21b6fbd382d206702efa8836a946eeab0b8ac25f5f22", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]},
|
||||
"db_connection": {:hex, :db_connection, "1.0.0-rc.3", "d9ceb670fe300271140af46d357b669983cd16bc0d01206d7d3222dde56cf038", [:mix], [{:sbroker, "~> 1.0.0-beta.3", [hex: :sbroker, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:connection, "~> 1.0.2", [hex: :connection, optional: false]}]},
|
||||
"decimal": {:hex, :decimal, "1.1.2", "79a769d4657b2d537b51ef3c02d29ab7141d2b486b516c109642d453ee08e00c", [:mix], []},
|
||||
"earmark": {:hex, :earmark, "1.0.1", "2c2cd903bfdc3de3f189bd9a8d4569a075b88a8981ded9a0d95672f6e2b63141", [:mix], []},
|
||||
"ecto": {:hex, :ecto, "2.0.2", "b02331c1f20bbe944dbd33c8ecd8f1ccffecc02e344c4471a891baf3a25f5406", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: true]}, {:sbroker, "~> 1.0-beta", [hex: :sbroker, optional: true]}, {:mariaex, "~> 0.7.7", [hex: :mariaex, optional: true]}, {:postgrex, "~> 0.11.2", [hex: :postgrex, optional: true]}, {:db_connection, "~> 1.0-rc.2", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}]},
|
||||
"eh": {:hex, :eh, "0.2.0"},
|
||||
"ex_doc": {:hex, :ex_doc, "0.11.3"},
|
||||
"poolboy": {:hex, :poolboy, "1.5.1"},
|
||||
"postgrex": {:hex, :postgrex, "0.10.0"}}
|
||||
"ex_doc": {:hex, :ex_doc, "0.13.0", "aa2f8fe4c6136a2f7cfc0a7e06805f82530e91df00e2bff4b4362002b43ada65", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
|
||||
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []},
|
||||
"postgrex": {:hex, :postgrex, "0.11.2", "139755c1359d3c5c6d6e8b1ea72556d39e2746f61c6ddfb442813c91f53487e8", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.0-rc", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
defmodule ISNTest do
|
||||
use ExUnit.Case, async: true
|
||||
import ISN.TestHelper
|
||||
alias Postgrex.Connection, as: P
|
||||
alias Postgrex, as: P
|
||||
|
||||
setup do
|
||||
options = Keyword.merge(conn_options, [extensions: [{ISN, {}}]])
|
||||
|
|
|
|||
|
|
@ -1,44 +1,28 @@
|
|||
ExUnit.start()
|
||||
|
||||
# db_options = [
|
||||
# hostname: "localhost",
|
||||
# database: "postgres"]
|
||||
#
|
||||
# db_user = System.get_env("DATABASE_POSTGRESQL_USERNAME")
|
||||
# db_pass = System.get_env("DATABASE_POSTGRESQL_PASSWORD")
|
||||
#
|
||||
# if db_user, do: db_options = Dict.put(db_options, :username, db_user)
|
||||
# if db_pass, do: db_options = Dict.put(db_options, :password, db_pass)
|
||||
#
|
||||
# {:ok, pid} = Postgrex.Connection.start_link(db_options)
|
||||
#
|
||||
# Postgrex.Connection.query!(pid, "DROP DATABASE IF EXISTS isn_test;", [])
|
||||
# Postgrex.Connection.query!(pid, "CREATE DATABASE isn_test;", [])
|
||||
# conn_options = Keyword.merge(db_options, [database: "isn_test"])
|
||||
# {:ok, pid} = Postgrex.Connection.start_link(conn_options)
|
||||
# Postgrex.Connection.query!(pid, "CREATE EXTENSION isn;", [])
|
||||
|
||||
defmodule ISN.TestHelper do
|
||||
def conn_options do
|
||||
db_options = [
|
||||
def conn_options do
|
||||
db_options = [
|
||||
sync_connect: true,
|
||||
hostname: "localhost",
|
||||
database: "isn_test",
|
||||
username: "postgres",
|
||||
password: ""]
|
||||
hostname: "localhost",
|
||||
database: "isn_test"]
|
||||
|
||||
db_user = System.get_env("DATABASE_POSTGRESQL_USERNAME")
|
||||
db_pass = System.get_env("DATABASE_POSTGRESQL_PASSWORD")
|
||||
db_user = System.get_env("DATABASE_POSTGRESQL_USERNAME")
|
||||
db_pass = System.get_env("DATABASE_POSTGRESQL_PASSWORD")
|
||||
|
||||
if db_user, do: db_options = Dict.put(db_options, :username, db_user)
|
||||
if db_pass, do: db_options = Dict.put(db_options, :password, db_pass)
|
||||
db_options =
|
||||
if db_user, do: db_options = Dict.put(db_options, :username, db_user),
|
||||
else: db_options
|
||||
db_options =
|
||||
if db_pass, do: db_options = Dict.put(db_options, :password, db_pass),
|
||||
else: db_options
|
||||
|
||||
db_options
|
||||
end
|
||||
db_options
|
||||
end
|
||||
|
||||
defmacro query(pid, statement, params) do
|
||||
quote bind_quoted: [pid: pid, statement: statement, params: params] do
|
||||
case Postgrex.Connection.query!(pid, statement, params, []) do
|
||||
case Postgrex.query!(pid, statement, params, []) do
|
||||
%Postgrex.Result{rows: nil} -> :ok
|
||||
%Postgrex.Result{rows: rows} -> rows
|
||||
%Postgrex.Error{} = err -> err
|
||||
|
|
@ -48,11 +32,9 @@ defmodule ISN.TestHelper do
|
|||
end
|
||||
|
||||
db_options = Keyword.merge(ISN.TestHelper.conn_options, [database: "postgres"])
|
||||
{:ok, pid} = Postgrex.Connection.start_link(db_options)
|
||||
{:ok, pid} = Postgrex.start_link(db_options)
|
||||
|
||||
Postgrex.Connection.query!(pid, "DROP DATABASE IF EXISTS isn_test;", [])
|
||||
Postgrex.Connection.query!(pid, "CREATE DATABASE isn_test;", [])
|
||||
Postgrex.Connection.stop(pid)
|
||||
{:ok, pid} = Postgrex.Connection.start_link(ISN.TestHelper.conn_options)
|
||||
Postgrex.Connection.query!(pid, "CREATE EXTENSION isn;", [])
|
||||
Postgrex.Connection.stop(pid)
|
||||
Postgrex.query!(pid, "DROP DATABASE IF EXISTS isn_test;", [])
|
||||
Postgrex.query!(pid, "CREATE DATABASE isn_test;", [])
|
||||
{:ok, pid} = Postgrex.start_link(ISN.TestHelper.conn_options)
|
||||
Postgrex.query!(pid, "CREATE EXTENSION isn;", [])
|
||||
|
|
|
|||
Loading…
Reference in New Issue