Class: PgEventstore::Web::Paginator::StreamIdsCollection
- Inherits:
-
BaseCollection
- Object
- BaseCollection
- PgEventstore::Web::Paginator::StreamIdsCollection
- Defined in:
- lib/pg_eventstore/web/paginator/stream_ids_collection.rb
Constant Summary collapse
- PER_PAGE =
10
Instance Attribute Summary
Attributes inherited from BaseCollection
#config_name, #options, #order, #per_page, #starting_id
Instance Method Summary collapse
Methods inherited from BaseCollection
#count, #initialize, #prev_page_starting_id, #total_count
Constructor Details
This class inherits a constructor from PgEventstore::Web::Paginator::BaseCollection
Instance Method Details
#collection ⇒ Array<Hash<String => String>>
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pg_eventstore/web/paginator/stream_ids_collection.rb', line 11 def collection @collection ||= begin sql_builder = SQLBuilder.new.select('stream_id').from('events') sql_builder.where('context = ? and stream_name = ?', [:context], [:stream_name]) sql_builder.where('stream_id like ?', "#{[:query]}%") sql_builder.where("stream_id #{direction_operator} ?", starting_id) if starting_id sql_builder.group('stream_id').limit(per_page).order("stream_id #{order}") connection.with do |conn| conn.exec_params(*sql_builder.to_exec_params) end.to_a end end |
#next_page_starting_id ⇒ String?
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pg_eventstore/web/paginator/stream_ids_collection.rb', line 26 def next_page_starting_id return unless collection.size == per_page starting_id = collection.first['stream_id'] sql_builder = SQLBuilder.new.select('stream_id').from('events') sql_builder.where("stream_id #{direction_operator} ?", starting_id) sql_builder.where('stream_id like ?', "#{[:query]}%") sql_builder.where('context = ? and stream_name = ?', [:context], [:stream_name]) sql_builder.group('stream_id').limit(1).offset(per_page).order("stream_id #{order}") connection.with do |conn| conn.exec_params(*sql_builder.to_exec_params) end.to_a.dig(0, 'stream_id') end |