Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sequel's <code>Dataset#each</code> does yield individual rows at a time, but most database drivers will load the entire result in memory first.</p> <p>If you are using Sequel's Postgres adapter, you can choose to use real cursors:</p> <pre><code>posts.use_cursor.each{|p| puts p} </code></pre> <p>This fetches 1000 rows at a time by default, but you can use an option to specify the amount of rows to grab per cursor fetch:</p> <pre><code>posts.use_cursor(:rows_per_fetch=&gt;100).each{|p| puts p} </code></pre> <p>If you aren't using Sequel's Postgres adapter, you can use Sequel's pagination extension:</p> <pre><code>Sequel.extension :pagination posts.order(:id).each_page(1000){|ds| ds.each{|p| puts p}} </code></pre> <p>However, like ActiveRecord's <code>find_in_batches</code>/<code>find_each</code>, this does separate queries, so you need to be careful if there are concurrent modifications to the dataset you are retrieving.</p> <p>The reason this isn't the default in Sequel is probably the same reason it isn't the default in ActiveRecord, which is that it isn't a good default in the general case. Only queries with large result sets really need to worry about it, and most queries don't return large result sets.</p> <p>At least with the Postgres adapter cursor support, it's fairly easy to make it the default for your model:</p> <pre><code>Post.dataset = Post.dataset.use_cursor </code></pre> <p>For the pagination extension, you can't really do that, but you can wrap it in a method that makes it mostly transparent.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload