I'm using Rails3.rc and Active Record 3 (with meta_where) and just started to switch to Sequel, because it seems to be much faster and offers some really great features.
I'm already using the active_model plugin (and some others).
As far as I know, I should use
User[params[:id]]
instead ofUser.find(params[:id])
. But this doesn't raise if no record exists and doesn't convert the value to an integer (type of PK), so it's as a string in thewhere
clause. I'm not sure if this is causing any performance issues. Does this harmidentity_map
? What's the best way to solve both these issues?Is there an easy way to flip the usage of associatio开发者_如何学Cns like
User.messages_dataset
andUser.messages
so thatUser.messages
behaves like in Active Record (User.messages_data_set
). I guess I'd use the#..._dataset
a lot but never need the array method, because I could just add.all
?I noticed some same (complex) queries are executed several times within one action sometimes. Is there something like the Active Record query cache? (
identity_map
doesn't seem to work for these cases).Is there a
to_sql
I can call to get the raw SQL a dataset would produce?
You can either use:
User[params[:id].to_i] || raise Sequel::Error
Or write your own method that does something like that. Sequel supports non-integer primary keys, so it wouldn't do the conversion automatically. It shouldn't have any affect on an identity map. Note that Sequel doesn't use an identity map unless you are using the identity_map plugin. I guess the best way is to write your own helper method.
Not really. You can use the
association_proxies
plugin so that non-array methods are sent to the dataset instead of the array of objects. In general, you shouldn't be using the association dataset method much. If you are using it a lot, it's a sign that you should have an association for that specific usage.There is and will never be a query cache. You should write your actions so that the results of the first query are cached and reused.
Dataset#sql
gives you theSELECT SQL
for the dataset.
精彩评论