-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from visciang/exql
Extensions
- Loading branch information
Showing
11 changed files
with
107 additions
and
50 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
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 @@ | ||
defmodule ExqlMigration.Schema do | ||
defmodule Exql.Migration.Schema do | ||
@moduledoc false | ||
|
||
@create_schema_stmt """ | ||
|
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,10 @@ | ||
defmodule Exql.Query do | ||
@moduledoc false | ||
|
||
@spec result(Postgrex.Result.t()) :: [map()] | ||
def result(%Postgrex.Result{columns: columns, rows: rows}) do | ||
Enum.map(rows, fn row -> | ||
Enum.zip(columns, row) |> Map.new() | ||
end) | ||
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
defmodule Test.Exql.Query do | ||
use ExUnit.Case | ||
alias Exql.Query | ||
|
||
@postgrex_conn :test | ||
|
||
@postgrex_conf [ | ||
hostname: System.get_env("POSTGRES_HOST", "localhost"), | ||
username: "postgres", | ||
password: "postgres", | ||
database: "postgres", | ||
name: @postgrex_conn | ||
] | ||
|
||
@test_table "query_test_table" | ||
|
||
setup_all do | ||
start_supervised!({Postgrex, @postgrex_conf}) | ||
|
||
Postgrex.query!(@postgrex_conn, "drop table if exists #{@test_table}", []) | ||
Postgrex.query!(@postgrex_conn, "create table #{@test_table} (x text, y text)", []) | ||
|
||
:ok | ||
end | ||
|
||
setup do | ||
on_exit(fn -> | ||
Postgrex.query!(@postgrex_conn, "truncate table #{@test_table}", []) | ||
end) | ||
end | ||
|
||
test "results zip" do | ||
Postgrex.query!(@postgrex_conn, "insert into #{@test_table} (x, y) values ('a', 'b')", []) | ||
|
||
res = Postgrex.query!(@postgrex_conn, "select * from #{@test_table}", []) | ||
assert [%{"x" => "a", "y" => "b"}] = Query.result(res) | ||
end | ||
end |