Ecto.Rut v1.0.2 Ecto.Rut

Provides simple, sane and terse shortcuts for Ecto models.

Ecto.Rut is a wrapper around Ecto.Repo methods that usually require you to pass the module as the subject and sometimes even require you do extra work before hand, (as in the case of Repo.insert/3) to perform operations on your database. Ecto.Rut tries to reduce code repetition by following the “Convention over Configuration” ideology.

For example, once set up, it allows you to do this on a model called Post:

# Create a Post
Post.insert(title: "Introduction to Elixir", categories: ["Elixir", "Programming"])

# Get all Posts
Post.all

# Get a Post with its id
Post.get(3)

# Get a Post with another attribute
Post.get_by(published_date: "2016-02-24")

# Delete a Post
Post.delete(lame_post)

Installation

Once added to your mix dependencies, all you need to do is call use Ecto.Rut in your Ecto models:

defmodule YourApp.Post do
  use Ecto.Schema
  use Ecto.Rut

  # Schema, Changeset and other stuff...
end

Phoenix Projects

If you’re using Ecto with a Phoenix project, instead of calling use Ecto.Rut in all of your models, you can just call it once in the model/0 method of your web/web.ex file:

# web/web.ex

def model do
  quote do
    use Ecto.Schema
    use Ecto.Rut

    # Other stuff...
  end
end