Public Instance methods
Yield datasets for subsets of the receiver that are limited to no more than 1000 rows (you can configure the number of rows using :rows_per_page
).
Options:
:rows_per_page |
The maximum number of rows in each yielded dataset (unless concurrent modifications are made to the table). |
# File lib/sequel/plugins/paged_operations.rb 91 def paged_datasets(opts=OPTS) 92 unless defined?(yield) 93 return enum_for(:paged_datasets, opts) 94 end 95 96 pk = _paged_operations_pk(:paged_update) 97 base_offset_ds = offset_ds = _paged_operations_offset_ds(opts) 98 first = nil 99 100 while last = offset_ds.get(pk) 101 ds = where(pk < last) 102 ds = ds.where(pk >= first) if first 103 yield ds 104 first = last 105 offset_ds = base_offset_ds.where(pk >= first) 106 end 107 108 ds = self 109 ds = ds.where(pk >= first) if first 110 yield ds 111 nil 112 end
Delete all rows of the dataset using using multiple queries so that no more than 1000 rows are deleted at a time (you can configure the number of rows using :rows_per_page
).
Options:
:rows_per_page |
The maximum number of rows affected by each DELETE query (unless concurrent modifications are made to the table). |
# File lib/sequel/plugins/paged_operations.rb 121 def paged_delete(opts=OPTS) 122 if (db.database_type == :oracle && !supports_fetch_next_rows?) || (db.database_type == :mssql && !is_2012_or_later?) 123 raise Error, "paged_delete is not supported on MSSQL/Oracle when using emulated offsets" 124 end 125 pk = _paged_operations_pk(:paged_delete) 126 rows_deleted = 0 127 offset_ds = _paged_operations_offset_ds(opts) 128 while last = offset_ds.get(pk) 129 rows_deleted += where(pk < last).delete 130 end 131 rows_deleted + delete 132 end
Update all rows of the dataset using using multiple queries so that no more than 1000 rows are updated at a time (you can configure the number of rows using :rows_per_page
). All arguments are passed to Dataset#update.
Options:
:rows_per_page |
The maximum number of rows affected by each UPDATE query (unless concurrent modifications are made to the table). |
# File lib/sequel/plugins/paged_operations.rb 142 def paged_update(values, opts=OPTS) 143 rows_updated = 0 144 paged_datasets(opts) do |ds| 145 rows_updated += ds.update(values) 146 end 147 rows_updated 148 end