Class: Ductr::SQLite::MatchLookup

Inherits:
ETL::BufferedTransform
  • Object
show all
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

Instance Method Details

#from_keySymbol

The looked up row key to match.

Returns:

  • (Symbol)

    The column name



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.

Yields:

  • (row)

    The each block

Yield Parameters:

  • row (Hash<Symbol, Object>)

    The merged row



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_keySymbol

The buffer row key to match.

Returns:

  • (Symbol)

    The column name



38
39
40
# File 'lib/ductr/sqlite/match_lookup.rb', line 38

def to_key
  @options[:merge].last
end