Skip to content

Commit

Permalink
Merge pull request #4 from pinx/master
Browse files Browse the repository at this point in the history
Allow `database` in config, instead of `database_name`
  • Loading branch information
mpoeter authored Mar 22, 2018
2 parents def02c6 + ccdb8ff commit 529b63d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ In the repository configuration, you need to specify the `:adapter`:
```elixir
config :my_app, MyApp.Repo,
adapter: ArangoDB.Ecto,
database_name: "my_app"
database: "my_app"
...
```

Expand All @@ -40,7 +40,7 @@ Unless specified otherwise, the show default values are used.
host: "localhost",
port: 8529,
scheme: "http",
database_name: "_system",
database: "_system",
arrango_version: 30_000,
headers: %{"Accept": "*/*"},
use_auth: :basic,
Expand Down Expand Up @@ -75,6 +75,7 @@ defmodule Post do
end
end
```

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
Expand All @@ -92,7 +93,9 @@ end
* on conflict
* upserts

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/arangodb_ecto](https://hexdocs.pm/arangodb_ecto).

## Testing
Before running the tests, configure access to your Arango database by setting
these environment variables:
- `ARANGO_SRV`
- `ARANGO_USR`
- `ARANGO_PWD`
13 changes: 7 additions & 6 deletions lib/arangodb_ecto/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ defmodule ArangoDB.Ecto.Utils do

@spec get_endpoint(Ecto.Adapter.repo, String.t | nil) :: Arangoex.Endpoint.t
def get_endpoint(repo, prefix \\ nil) do
config = repo.config
config = if prefix == nil,
do: config,
else: Keyword.put(config, :database_name, prefix)

config = repo.config()
database = prefix || Keyword.get(config, :database) || Keyword.get(config, :database_name)
config =
config
|> Keyword.put(:database_name, database)

struct(Arangoex.Endpoint, config)
end
end
end
4 changes: 2 additions & 2 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ alias Ecto.Integration.TestRepo

Application.put_env(:ecto, TestRepo,
adapter: ArangoDB.Ecto,
database_name: "test")
database: "test")

defmodule Ecto.Integration.TestRepo do
use Ecto.Integration.Repo, otp_app: :ecto
Expand Down Expand Up @@ -74,4 +74,4 @@ _ = ArangoDB.Ecto.storage_down(PoolRepo.config)
:ok = Ecto.Migrator.up(PoolRepo, 0, Ecto.Integration.Migration, log: false)


Process.flag(:trap_exit, true)
Process.flag(:trap_exit, true)

0 comments on commit 529b63d

Please sign in to comment.