Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ GenStage.sync_subscribe(consumer, to: producer)

Refer to the [documentation](https://hexdocs.pm/bourne/Bourne.html).

## Testing

The test suite relies on a locally running postgres insatnce. You can use docker to create one quickly:

```
docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -d postgres
```

## License

Bourne is free and unencumbered software released into the public domain, with fallback provisions for jurisdictions that don't recognize the public domain.
Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use Mix.Config

[]
import_config "#{Mix.env()}.exs"
1 change: 1 addition & 0 deletions config/dev.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
9 changes: 9 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use Mix.Config
config :bourne, ecto_repos: [Bourne.Test.Repo]

config :bourne, Bourne.Test.Repo,
database: "bourne_test",
username: "postgres",
password: "postgres",
hostname: "localhost",
port: "5432"
99 changes: 53 additions & 46 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,65 +1,72 @@
defmodule Bourne.Mixfile do
use Mix.Project

@version File.read!("VERSION") |> String.trim_trailing
@version File.read!("VERSION") |> String.trim_trailing()
@source "https://github.com/mtwilliams/bourne"

def project do [
app: :bourne,
elixir: "~> 1.4",
elixirc_paths: elixirc_paths(Mix.env),
config_path: "config/config.exs",
build_path: "_build",
deps_path: "_deps",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps(),
package: package(),
name: "Bourne for Ecto",
description: "Better streaming for Ecto.",
version: @version,
docs: docs(),
homepage_url: @source,
source_url: @source,
test_coverage: [tool: ExCoveralls]
] end
def project do
[
app: :bourne,
elixir: "~> 1.4",
elixirc_paths: elixirc_paths(Mix.env()),
config_path: "config/config.exs",
build_path: "_build",
deps_path: "_deps",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps(),
package: package(),
name: "Bourne for Ecto",
description: "Better streaming for Ecto.",
version: @version,
docs: docs(),
homepage_url: @source,
source_url: @source,
test_coverage: [tool: ExCoveralls]
]
end

def application do
[applications: applications(Mix.env)]
[applications: applications(Mix.env())]
end

defp applications(:test), do: [:postgrex, :ecto, :logger]
defp applications(_), do: [:ecto, :logger]

defp deps do [
{:ecto, "~> 2.1"},

# Testing
{:postgrex, "~> 0.13", only: [:test]},
{:gen_stage, "~> 0.13", only: [:test]},
defp deps do
[
{:ecto_sql, "~> 3.0"},

{:excoveralls, ">= 0.0.0", only: [:test]},
{:inch_ex, ">= 0.0.0", only: [:dev, :docs]},
# Testing
{:postgrex, ">= 0.0.0"},
{:gen_stage, "~> 0.13", only: [:test]},
{:excoveralls, ">= 0.0.0", only: [:test]},
{:inch_ex, ">= 0.0.0", only: [:dev, :docs]},

# Documentation
{:ex_doc, "~> 0.15", only: [:dev, :docs]},
{:earmark, "~> 1.1", only: [:dev, :docs]}
] end
# Documentation
{:ex_doc, "~> 0.15", only: [:dev, :docs]},
{:earmark, "~> 1.1", only: [:dev, :docs]}
]
end

defp elixirc_paths(_), do: ~W{lib}

defp package do [
maintainers: ["Michael Williams"],
licenses: ["Public Domain"],
links: %{"Github" => @source},
files: ~w(lib mix.exs README.md LICENSE CHANGELOG.md VERSION)
] end
defp package do
[
maintainers: ["Michael Williams"],
licenses: ["Public Domain"],
links: %{"Github" => @source},
files: ~w(lib mix.exs README.md LICENSE CHANGELOG.md VERSION)
]
end

defp docs do [
main: "Bourne",
canonical: "http://hexdocs.pm/bourne",
source_ref: "v#{@version}",
source_url: @source,
extras: ~W{README.md CHANGELOG.md}
] end
defp docs do
[
main: "Bourne",
canonical: "http://hexdocs.pm/bourne",
source_ref: "v#{@version}",
source_url: @source,
extras: ~W{README.md CHANGELOG.md}
]
end
end
45 changes: 25 additions & 20 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
%{
"certifi": {:hex, :certifi, "1.0.0", "1c787a85b1855ba354f0b8920392c19aa1d06b0ee1362f9141279620a5be2039", [:rebar3], []},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], []},
"db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
"decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.1.1", "433136b7f2e99cde88b745b3a0cfc3fbc81fe58b918a09b40fce7f00db4d8187", [:mix], []},
"ecto": {:hex, :ecto, "2.1.3", "ffb24e150b519a4c0e4c84f9eabc8587199389bc499195d5d1a93cd3b2d9a045", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
"ex_doc": {:hex, :ex_doc, "0.15.0", "e73333785eef3488cf9144a6e847d3d647e67d02bd6fdac500687854dd5c599f", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
"excoveralls": {:hex, :excoveralls, "0.6.2", "0e993d096f1fbb6e70a3daced5c89aac066bda6bce57829622aa2d1e2b338cfb", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]},
"gen_stage": {:hex, :gen_stage, "0.14.0", "65ae78509f85b59d360690ce3378d5096c3130a0694bab95b0c4ae66f3008fad", [:mix], [], "hexpm"},
"hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, optional: false]}, {:idna, "4.0.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
"idna": {:hex, :idna, "4.0.0", "10aaa9f79d0b12cf0def53038547855b91144f1bfcc0ec73494f38bb7b9c4961", [:rebar3], []},
"inch_ex": {:hex, :inch_ex, "0.5.6", "418357418a553baa6d04eccd1b44171936817db61f4c0840112b420b8e378e67", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, optional: false]}]},
"jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []},
"postgrex": {:hex, :postgrex, "0.13.5", "3d931aba29363e1443da167a4b12f06dcd171103c424de15e5f3fc2ba3e6d9c5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
"db_connection": {:hex, :db_connection, "2.0.5", "ddb2ba6761a08b2bb9ca0e7d260e8f4dd39067426d835c24491a321b7f92a4da", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
"decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "3.0.7", "44dda84ac6b17bbbdeb8ac5dfef08b7da253b37a453c34ab1a98de7f7e5fec7f", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"},
"ecto_sql": {:hex, :ecto_sql, "3.0.5", "7e44172b4f7aca4469f38d7f6a3da394dbf43a1bcf0ca975e958cb957becd74e", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.6", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.3.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.19.3", "3c7b0f02851f5fc13b040e8e925051452e41248f685e40250d7e40b07b9f8c10", [:mix], [{:earmark, "~> 1.2", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.10.6", "e2b9718c9d8e3ef90bc22278c3f76c850a9f9116faf4ebe9678063310742edc2", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"gen_stage": {:hex, :gen_stage, "0.14.1", "9d46723fda072d4f4bb31a102560013f7960f5d80ea44dcb96fd6304ed61e7a4", [:mix], [], "hexpm"},
"hackney": {:hex, :hackney, "1.15.1", "9f8f471c844b8ce395f7b6d8398139e26ddca9ebc171a8b91342ee15a19963f4", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"inch_ex": {:hex, :inch_ex, "2.0.0", "24268a9284a1751f2ceda569cd978e1fa394c977c45c331bb52a405de544f4de", [:mix], [{:bunt, "~> 0.2", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.14.1", "63247d4a5ad6b9de57a0bac5d807e1c32d41e39c04b8a4156a26c63bcd8a2e49", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"},
"telemetry": {:hex, :telemetry, "0.3.0", "099a7f3ce31e4780f971b4630a3c22ec66d22208bc090fe33a2a3a6a67754a73", [:rebar3], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
}
16 changes: 5 additions & 11 deletions priv/repo/migrations/1_setup.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,17 @@ defmodule Bourne.Test.Repo.Migrations.Setup do

def change do
create table(:actors) do
add :name, :string

timestamps()
add(:name, :string)
end

create table(:movies) do
add :title, :string
add :year, :integer

timestamps()
add(:title, :string)
add(:year, :integer)
end

create table(:credits) do
add :actor_id, references(:actors)
add :movie_id, references(:movies)

timestamps()
add(:actor_id, references(:actors))
add(:movie_id, references(:movies))
end
end
end
5 changes: 4 additions & 1 deletion test/support/repo.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule Bourne.Test.Repo do
use Ecto.Repo, otp_app: :bourne
use Ecto.Repo,
otp_app: :bourne,
adapter: Ecto.Adapters.Postgres

use Bourne
end
24 changes: 9 additions & 15 deletions test/support/schema.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,30 @@ defmodule Bourne.Test.Actor do
use Ecto.Schema

schema "actors" do
field :name, :string
field(:name, :string)

has_many :credits, Bourne.Test.Credit
has_many :movies, through: [:credits, :movie]

timestamps()
has_many(:credits, Bourne.Test.Credit)
has_many(:movies, through: [:credits, :movie])
end
end

defmodule Bourne.Test.Movie do
use Ecto.Schema

schema "movies" do
field :title, :string
field :year, :integer

has_many :credits, Bourne.Test.Credit
has_many :actors, through: [:credits, :actor]
field(:title, :string)
field(:year, :integer)

timestamps()
has_many(:credits, Bourne.Test.Credit)
has_many(:actors, through: [:credits, :actor])
end
end

defmodule Bourne.Test.Credit do
use Ecto.Schema

schema "credits" do
belongs_to :actor, Bourne.Test.Actor
belongs_to :movie, Bourne.Test.Movie

timestamps()
belongs_to(:actor, Bourne.Test.Actor)
belongs_to(:movie, Bourne.Test.Movie)
end
end
9 changes: 5 additions & 4 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
Logger.configure(level: :info)

# TODO(mtwilliams): Test against other adapters.
Application.put_env :bourne, Bourne.Test.Repo, [
Application.put_env(:bourne, Bourne.Test.Repo,
adapter: Ecto.Adapters.Postgres,
url: System.get_env("DATABASE_URL") || "ecto://postgres:postgres@localhost/bourne",
pool: Ecto.Adapters.SQL.Sandbox
]
)

for file <- ~W{support/repo.exs support/schema.exs support/data.exs support/case.exs} do
Code.require_file(file, __DIR__)
end

# Reset backing storage, start the repository, and run migration.
_ = Ecto.Adapters.Postgres.storage_down(Bourne.Test.Repo.config)
:ok = Ecto.Adapters.Postgres.storage_up(Bourne.Test.Repo.config)
_ = Ecto.Adapters.Postgres.storage_down(Bourne.Test.Repo.config())
:ok = Ecto.Adapters.Postgres.storage_up(Bourne.Test.Repo.config())

{:ok, _} = Bourne.Test.Repo.start_link()
{:ok, _} = Application.ensure_all_started(:ecto_sql)

migrations = Path.join(:code.priv_dir(:bourne), "/repo/migrations")
migration = Path.join(migrations, "1_setup.exs")
Expand Down