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.
相关问题
- NOT DISTINCT query in mySQL
- Flush single app django 1.9
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
相关文章
- 用哪个ORM好点,博客园用的什么
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- Hibernate doesn't generate cascade
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
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)It seems that it is possible to use different databases in most of ORMs. For DataMapper look at knowtheory answer. For Sequel you can pass database handler to model:
where db is opened database. For ActiveRecord you can use establish_connection method.
Personally I prefer Sequel for all my ORM and basic database accesses and is what I use with Sinatra/Padrino and any other time I need to access a database outside of Rails.
I've used DataMapper but felt Sequel was easier and more flexible, but maybe that's just how my mind works. ActiveRecord is OK on its own, but I think it works best in combination with Rails.
Which is "better"? I think that is subjective and mostly is tied to how your brain works.