EctoSharding v0.0.5 EctoSharding.Repo View Source
An Ecto.Repo
wrapper. This should be used in place of use Ecto.Repo
.
This implements the same interface as Ecto.Repo
and should be used in the
same way.
Example
defmodule MyApp.Repo do
use EctoSharding.Repo, otp_app: :my_app
end
defmodule MyApp.Account do
use Ecto.Schema, sharded: false
schema "accounts" do
field :name, :string
has_many :users, MyApp.User
end
end
defmodule MyApp.User do
use Ecto.Schema
schema "users" do
field :name, :string
field :email, :string
belongs_to :account, MyApp.Account
end
end
# Fetch an account and preload all of its users
MyApp.Account
|> MyApp.Repo.get(1)
|> MyApp.Repo.preload([:users])
%MyApp.Account{name: "Account 1",
users: [%MyApp.User{name: "User 1", email: "user1@example.com"}]}