简体   繁体   English

如何使用Hanami / Repository访问多个数据库

[英]How can I access more than one database with Hanami/Repository

I have a application that has to generate reports from a data warehouse. 我有一个必须从数据仓库生成报告的应用程序。
I don't want to save the app specific data (user, permissions, report defintions, ...) in the same database where the warehouse lives. 我不想将应用程序特定数据(用户,权限,报告定义......)保存在仓库所在的同一数据库中。 Also, in the future it is very likely that I have to get access to other databases as well (maybe even Oracle). 此外,将来我很可能也必须访问其他数据库(甚至可能是Oracle)。
I have configured my database connection in the .env files but I don't know if or where I can define a new connection and also how to instanciate a repository for this explicit connection. 我已经在.env文件中配置了我的数据库连接,但我不知道我是否可以定义新连接,以及如何为此显式连接实例化存储库。
Since this is the 2nd container from my app, I was wondering if it is possible to change the orm for one container, when hanami-model isn't suited for my needs... 由于这是我的应用程序中的第二个容器,我想知道是否可以更改一个容器的orm,当hanami-model不适合我的需求时...

This is an example how to connect to two databases using hanami: 这是一个如何使用hanami连接到两个数据库的示例:

require 'pg'
require 'hanami/model'
require 'hanami/model/adapters/sql_adapter'

mapper = Hanami::Model::Mapper.new do
  # ...
end

adapter1 = Hanami::Model::Adapters::SqlAdapter.new(mapper, 'postgres://host:port/database1')

adapter2 = Hanami::Model::Adapters::SqlAdapter.new(mapper, 'postgres://host:port/database2')


DataRepository.adapter  = adapter1
UserRepository.adapter = adapter2

I'm sorry, you can't connect to more than one database per project at this time. 对不起,您目前无法为每个项目连接到多个数据库。 We're evaluating this feature after 1.0. 我们在1.0之后评估此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM