什么ORM在一个进程中使用多个db连接sinatra应用程序? [英] What ORM to use in one process multiple db connections sinatra application?

查看:104
本文介绍了什么ORM在一个进程中使用多个db连接sinatra应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查ActiveRecord,DataMapper,Sequel:一些使用全局变量(静态变量)一些需要打开数据库连接之前加载源文件与模型。什么ORM在使用不同数据库的sinatra应用程序中更好。

解决方案

DataMapper是为多数据库使用而设计的。 p>

只需说出 DataMapper.setup(:repository_one,mysql:// localhost / my_db_name)



然后,DataMapper会跟踪您可以引用并用于范围设定的哈希中设置的所有存储库:



DataMapper.repository(:repository_one){MyModel.all}



范围只是DataMapper.repository,你可以通过 DataMapper.setup(:default,postgres:// localhost / my_primary_db)等等设置 p>

Checked ActiveRecord, DataMapper, Sequel: some use globals (static variables) some require open db connection before loading source file with models. What ORM is better to use in sinatra application that uses different databases.

解决方案

DataMapper is designed for multi-database use.

You can set up multiple repositories just by saying something like DataMapper.setup(:repository_one, "mysql://localhost/my_db_name").

DataMapper then tracks all the repositories that have been setup in a hash that you can reference and use for scoping:

DataMapper.repository(:repository_one){ MyModel.all }

(The default scope just being DataMapper.repository, which you can set up by saying DataMapper.setup(:default, "postgres://localhost/my_primary_db") or the like)

这篇关于什么ORM在一个进程中使用多个db连接sinatra应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆