• Stars
    star
    4
  • Rank 3,198,598 (Top 65 %)
  • Language
    Elixir
  • License
    Apache License 2.0
  • Created about 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Ecto adapter for the Ravix RavenDB Driver

Ravix Ecto

Build & Tests

RavenDB is an amazing multi-model NoSQL database, and albeit it does not support SQL, its RQL Language if pretty close, so behold, now you can query it like a simple Ecto-SQL database.

This adapter leverages the use of Ravix as a driver between ecto and RavenDB

Installing

Add Ravix Ecto to your mix.exs dependencies

{:ravix_ecto, "~> 0.4.0"}

Example

# In your config/config.exs file
config :my_app, Store,
  urls: [System.get_env("RAVENDB_URL", "http://localhost:8080")],
  database: "test",
  retry_on_failure: true,
  retry_on_stale: true,
  retry_backoff: 500,
  retry_count: 3,
  force_create_database: true,
  document_conventions: %{
    max_number_of_requests_per_session: 30,
    max_ids_to_catch: 32,
    timeout: 30,
    use_optimistic_concurrency: false,
    max_length_of_query_using_get_url: 1024 + 512,
    identity_parts_separator: "/",
    disable_topology_update: false
  }

config :my_app, Repo, store: Store

# In your application code
defmodule Store do
  use Ravix.Documents.Store, otp_app: :my_app
end

defmodule Repo do
  use Ecto.Repo,
    otp_app: :ravix_ecto,
    adapter: Ravix.Ecto.Adapter
end

defmodule TestApplication do
  use Application

  def start(_opts, _) do
    children = [
      {Repo, [%{}]}
    ]

    Supervisor.init(
      children,
      strategy: :one_for_one
    )
  end
end

defmodule Weather do
  use Ecto.Model

  @primary_key {:id, :binary_id, autogenerate: true}
  schema "weather" do
    field :city     # Defaults to type :string
    field :temp_lo, :integer
    field :temp_hi, :integer
    field :prcp,    :float, default: 0.0
  end
end

defmodule Simple do
  import Ecto.Query

  def sample_query do
    query = from w in Weather,
          where: w.prcp > 0 or is_nil(w.prcp),
         select: w
    Repo.all(query)
  end
end

Caveats

RavenDB does not support integer ids

In RavenDB all the IDs are strings, so the :id type will generate a non-integer type

Aggregations on RavenDB are different

In RavenDB the aggregations use a Map-Reduce index based aggregation, which gets a bit annoying to deal using Ecto, so for now, you can only do aggregations using Ravix Directly.

Conflicts management

RavenDB deals a bit different with conflicts, so right now if you have a conflict, an exception will be raised. Ecto strategies are not supported yet.

Associations

RavenDB is a Document-Database first, it does support a kind of documents association, but i've not implemented it yet (mostly because i think relationships in documents sucks). You can however use embed schemas normally.

Migrations

RavenDB is schemaless, so migrations are kind of useless. We can however use it to setup indexes and so on, but it's not implemented yet.

TODOs

  • Aggregations
  • Conflict Management
  • Associations

Contributors

mongodb_ecto - From who i shamelessly forked and adapted this driver, that saved me a lot of work : D