phoenix-framework - Elixir/Phoenix - Connect to external database
问题描述
I connected the main database in the dev.exs and it works fine. But in my project I plan to use several databases. I know that in the file dev.exs can connect multiple databases but this option doesn’t suit me. Databases connections will be stored in the main project database. I want to know: how can I connect to different databases using the elixir code without using a file dev.exs?
解决方案
You can start multiple instances of your Repo with different connection options.
Then, use the Repo.put_dynamic_repo/1
function to tell the Repo which of the databases should be used for queries in the current process. (The documentation for this function also tells you how to start more of the same repo).
There's also a discussion document that goes more in-depth about this topic: https://hexdocs.pm/ecto/replicas-and-dynamic-repositories.html
推荐阅读
- php - 无法使用php在webform的下一页上传递用户的输入值
- python - sk学习,当我要预测的数据与我现在拥有的数据分布不同时该怎么办
- linux - 为什么 perf 不报告“dcache-store-misses”?
- java - 这种方法的时间复杂度是多少?
- android - 带有外部 GPS 的自定义位置服务通过 android things 连接到 Raspberry Pi
- sql - postgres 中的二维列是否已弃用?
- c# - 如何为具有多对多关系的数据编写get方法
- javascript - WordPress Divi 主题 jQuery 代码冲突
- python - Python 的 recvfrom() 函数不返回任何数据
- javascript - 如何将字符串转换为 Typescript 中的枚举