postgresql 在独立的 ruby 应用程序中使用哪个 ruby ORM 框架?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1001040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which ruby ORM framework to use in a standalone ruby app?
提问by JtR
I would like to use postgresql with foreign keys to define relationships in data so that other platforms/apps would also be able to easily use the same database. Having some kind of ruby DSL to define database schema with migration support would also be great. Which framework would you recommend for me?
我想使用带有外键的 postgresql 来定义数据中的关系,以便其他平台/应用程序也能够轻松使用相同的数据库。拥有某种 ruby DSL 来定义具有迁移支持的数据库模式也很棒。你会为我推荐哪个框架?
Is there some kind of framework for only handling database schema changes, migrations and versions separate of ORM?
是否有某种框架仅用于处理 ORM 之外的数据库架构更改、迁移和版本?
采纳答案by Jonas Elfstr?m
Check out DataMapper. I recently used itwith Sinatra and deployed the app to Heroku. The only SQL I had to write was CREATE DATABASE. Everything else DataMapper provided for me with the .auto_migrate! and .auto_upgrade! functionality.
查看DataMapper。我最近将它与 Sinatra 一起使用并将应用程序部署到 Heroku。我必须编写的唯一 SQL 是 CREATE DATABASE。DataMapper 通过 .auto_migrate 为我提供的所有其他内容!和 .auto_upgrade!功能。
The foreign key support is in the dm-constraints plugin.
外键支持在 dm-constraints 插件中。
回答by SztupY
Between ActiveRecord and DataMapper I'd chose the latter. Both use the Active Record pattern, so you'll actually get your database tables back in objects without fancy domain logic, but DataMapper is way easier to work with, and is thread-safe. There is also Sequel, but which I'm not familiar with.
在 ActiveRecord 和 DataMapper 之间,我选择了后者。两者都使用 Active Record 模式,因此您实际上可以在没有花哨的域逻辑的情况下将数据库表恢复到对象中,但是 DataMapper 更易于使用,并且是线程安全的。还有Sequel,但我不熟悉。
If you need a framework to handle migrations I'd advise merb. Althoug it's a complete web framework starting 1.1 it can handle migrations for the three previously mentioned ORM framework (including separate and auto migrations)
如果您需要一个框架来处理迁移,我建议您使用merb。虽然它是一个完整的 Web 框架,从 1.1 开始它可以处理前面提到的三个 ORM 框架的迁移(包括单独和自动迁移)
回答by Pistos
回答by DanSingerman
Is there a good reason not to use ActiveRecord? It's kind of a standard for Ruby...
有充分的理由不使用ActiveRecord吗?这是Ruby的一种标准......