I want to use Ecto in my application, but with distinctive connections to the database, since every user of the application has a corresponding database user.
Now there seems to be Ecto.Repo.put_dynamic_repo(), but I do seem to do something wrong and furthermore this functionality is marked “experimental”. I currently have a solution which does that, but I’m missing out on a lot of stuff, since I’m always reinventing the wheel (e.g. CRUD stuff in Phoenix, and everyhting else there is when using “raw” Postgrex).
I’m trying the following:
iex(1)> DBRepo.start_link(name: :admin, username: "admin", database: "db", hostname: "localhost")
{:ok, #PID<0.247.0>}
iex(2)> DBRepo.put_dynamic_repo(:admin)
DBRepo
iex(3)> DBRepo.get_dynamic_repo
:admin
iex(4)> DBRepo.query("select * from users")
** (RuntimeError) could not lookup DBRepo because it was not started or it does not exist
(ecto) lib/ecto/repo/registry.ex:18: Ecto.Repo.Registry.lookup/1
(ecto) lib/ecto/adapter.ex:127: Ecto.Adapter.lookup_meta/1
(ecto_sql) lib/ecto/adapters/sql.ex:334: Ecto.Adapters.SQL.query/4
What am I doing wrong here and is Ecto.Repo.put_dynamic_repo() really the only way? Especially as it is marked “experimental”?
Thanks in advance…