# NebulexEcto
> ### Ecto & Nebulex Integration
> Ecto Cacheable Repo with Nebulex

[![Build Status](](
[![Coverage Status](](
[![Inline docs](](

A project that integrates [Nebulex](
with [Ecto]( out-of-box.

## Installation

Add `nebulex_ecto` to your list dependencies in `mix.exs`:

def deps do
    {:nebulex_ecto, "~> 0.1"}

## Example

Suppose you have an Ecto repo:

defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Ecto.Adapters.Postgres

And a Nebulex cache:

defmodule MyApp.Cache do
  use Nebulex.Cache,
    otp_app: :my_app,
    adapter: Nebulex.Adapters.Local

The idea is to encapsulate both in a single module by means of
`NebulexEcto.Repo`, like so:

defmodule MyApp.CacheableRepo do
  use NebulexEcto.Repo,
    cache: MyApp.Cache,
    repo: MyApp.Repo

Now we can use `MyApp.CacheableRepo` as a regular Ecto repo, of course,
there are some constraints, [`NebulexEcto.Repo`](lib/nebulex_ecto/repo.ex)
only provides some of the `Ecto.Repo` functions (the basic ones – get, get_by,
insert, update, delete, etc.), [please check them out before](lib/nebulex_ecto/repo.ex).

Usage example:

First, let's define a schema:

defmodule MyApp.MySchema do
  use Ecto.Schema

  schema "my_schema" do
    field :x, :string
    field :y, :binary
    field :z, :string, default: "z"

Now we can play with it:

schema = %MyApp.MySchema{x: "abc"}

{:ok, schema} = MyApp.CacheableRepo.insert(schema)


MyApp.CacheableRepo.get_by!(MyApp.MySchema, [id:])

changeset = Ecto.Changeset.change schema, x: "New"
{:ok, schema} = MyApp.CacheableRepo.update(changeset)


## Running Tests

To run the tests:

$ mix test

Running tests with coverage:

$ mix coveralls.html

And you can check out the coverage result in `cover/excoveralls.html`.