April 2019
Beginner to intermediate
244 pages
6h 34m
English
Most of the time, your apps will only have to work with one database, so you’ll just need one repo. But sometimes you’ll need to connect to multiple databases, and in those cases, you’ll need to set up a separate repo for each database. Ecto has good support for this scenario. First, you need to create the new repo:
| | defmodule MyApp.OtherRepo do |
| | use Ecto.Repo, otp_app: :my_app, adapter: Ecto.Adapter.Postgres |
| | end |
Then you need to configure it, just like you did with the first repo:
| | config :my_app, MyApp.OtherRepo, ... |
| | |
| | config :my_app, :ecto_repos, [MyApp.Repo, MyApp.OtherRepo] |
Finally, add the new repo to your application’s supervision tree:
| | children = [ |
Read now
Unlock full access