isn/test/test_helper.exs

27 lines
801 B
Elixir
Raw Normal View History

2015-05-05 20:15:40 +00:00
ExUnit.start()
{:ok, pid} = Postgrex.Connection.start_link(
hostname: "localhost",
database: "postgres"
)
Postgrex.Connection.query!(pid, "DROP DATABASE IF EXISTS isn_test;", [])
Postgrex.Connection.query!(pid, "CREATE DATABASE isn_test;", [])
{:ok, pid} = Postgrex.Connection.start_link(
hostname: "localhost",
database: "isn_test"
)
Postgrex.Connection.query!(pid, "CREATE EXTENSION isn;", [])
defmodule Isn.TestHelper do
defmacro query(pid, statement, params) do
quote bind_quoted: [pid: pid, statement: statement, params: params] do
case Postgrex.Connection.query(pid, statement, params, []) do
{:ok, %Postgrex.Result{rows: nil}} -> :ok
{:ok, %Postgrex.Result{rows: rows}} -> rows
{:error, %Postgrex.Error{} = err} -> err
end
end
end
end