Class: Ductr::SQLite::MatchLookup
- Inherits:
-
ETL::BufferedTransform
- Object
- ETL::BufferedTransform
- Ductr::SQLite::MatchLookup
- Defined in:
- lib/ductr/sqlite/match_lookup.rb
Overview
A lookup control that execute the query for a bunch of rows, registered as :match
.
Accept the :buffer_size
option, default value is 10 000.
Accept the :merge
option, mandatory an array with two entries:
- The first one is the looked up row key to match.
- The second one is the buffer row key to match.
Unless the :buffered
lookup, this one abstracts the row matching logic by assuming that
you want to merge rows based on a key couple e.g. primary / foreign keys:
lookup :some_sqlite_database, :match, merge: [:id, :item], buffer_size: 42 def merge_with_stuff(db, ids) db[:items_bis].where(item: ids) end
Instance Method Summary collapse
-
#from_key ⇒ Symbol
The looked up row key to match.
-
#on_flush {|row| ... } ⇒ void
Opens the database if needed, calls the job's method and merges the looked up rows with corresponding buffer rows.
-
#to_key ⇒ Symbol
The buffer row key to match.
Instance Method Details
#from_key ⇒ Symbol
The looked up row key to match.
29 30 31 |
# File 'lib/ductr/sqlite/match_lookup.rb', line 29 def from_key @options[:merge].first end |
#on_flush {|row| ... } ⇒ void
This method returns an undefined value.
Opens the database if needed, calls the job's method and merges the looked up rows with corresponding buffer rows.
51 52 53 54 55 56 57 58 |
# File 'lib/ductr/sqlite/match_lookup.rb', line 51 def on_flush(&) call_method(adapter.db, buffer_keys).each do |row| match = buffer_find(row) next yield(row) unless match yield(row.merge match) end end |
#to_key ⇒ Symbol
The buffer row key to match.
38 39 40 |
# File 'lib/ductr/sqlite/match_lookup.rb', line 38 def to_key @options[:merge].last end |