English 中文(简体)
是否使用过治疗器或智能手法?
原标题:Are there any Ruby ORMs which use cursors or smart fetch?

I m 要求Ruby ORM取代“积极记录”。 我一直在研究Sequel和数据Mapper。 然而,他们看上去看不到什么基本东西:在你不需要时,不要把所有东西装上记忆。

我指的是,我以几行之分在桌旁对“积极记录”和“后遗症”进行了如下(或等同)审判:

 posts.each { |p| puts p }

两人都记忆犹新。 他们似乎装上一切的记忆,而不是在需要时打脚。 我在主动查阅中使用<代码>find_in_batches,但这不是一个可以接受的解决办法:

  1. ActiveRecord is not an acceptable solution because we had too many problems with it.
  2. Why should my code be aware of a paging mechanism? I m happy to configure somewhere the size of the page but that s it. With find_in_batches you need to do something like:

    员额:find_ches{>batch batch.each{> > > >

But that should be transparent.

因此,在什么地方有一个可靠的Ruby ORM?


Update:

As Sergio mentioned, in Rails 3 you can use find_each which exactly what I want. However as ActiveRecord is not an option, except if someone can really convince me to use it, the questions are:

  1. Which ORMs support the equivalent of find_each?
  2. How to do it?
  3. Why do we need a find_each, while find should do it, shouldn t it?
最佳回答

Sequel s Dataset#each在某一时间产生单行,但大多数数据库司机将首先装载全部结果。

If you are using Sequel s Postgres adapter, you can choose to use real cursors:

posts.use_cursor.each{|p| puts p}

在发生违约时,每排1 000个牢房,但你可以采用一种办法,确定每座曲线 gr鱼的数量:

posts.use_cursor(:rows_per_fetch=>100).each{|p| puts p}

If you aren t using Sequel s Postgres adapter, you can use Sequel s pagination extension:

Sequel.extension :pagination
posts.order(:id).each_page(1000){|ds| ds.each{|p| puts p}}

然而,正如“积极记录”栏目中定义的_in_batches/ find_each一样,这确实有不同的疑问,因此,如果同时对数据集进行改动,则需要谨慎处理。

造成塞克尔省违约的原因很可能是“积极记录”中的缺省,也就是说,在一般情况下,这是不好的违约。 只有提出大量结果的询问才真正需要担心,大多数询问不会回去大量结果。

至少在Pogres改造者治疗器的支持下,很容易使它成为你模式的缺失:

Post.dataset = Post.dataset.use_cursor

就扩大想象力而言,你确实可以这样做,但你可以总结一下这种方法,使之最透明。

问题回答
Sequel.extension :pagination
posts.order(:id).each_page(1000) do |ds|
  ds.each { |p| puts p }
end

大型会议非常缓慢!

It becomes clear, looked at the method body: http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Dataset.html#method-i-paginate

# File lib/sequel/extensions/pagination.rb, line 11

def paginate(page_no, page_size, record_count=nil)
  raise(Error, "You cannot paginate a dataset that already has a limit") if @opts[:limit]
  paginated = limit(page_size, (page_no - 1) * page_size)
  paginated.extend(Pagination)
  paginated.set_pagination_info(page_no, page_size, record_count || count)
end

活性记录实际上几乎透明:batch Mode:

User.find_each do |user|
  NewsLetter.weekly_deliver(user)
end

该守则比在积极记录中发现的批量更快。

id_max = table.get(:max[:id])
id_min = table.get(:min[:id])
n=1000
(0..(id_max-id_min)/n).map.each do |i|
    table.filter(:id >= id_min+n*i, :id < id_min+n*(i+1)).each {|row|}
end

可考虑Ohm,其基础是Redis NoSQL Store。





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签