Are there any Ruby ORMs which use cursors or smart fetch?

前端 未结 5 549
误落风尘
误落风尘 2021-02-05 07:36

I\'m looking for a Ruby ORM to replace ActiveRecord. I\'ve been looking at Sequel and DataMapper. They look pretty good however none of them seems to do the basic: not loading e

5条回答
  •  长发绾君心
    2021-02-05 08:00

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

    It is very very slow on large tables!

    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
    

提交回复
热议问题