Class: Drudgery::Extractors::SQLite3Extractor
- Inherits:
-
Object
- Object
- Drudgery::Extractors::SQLite3Extractor
- Defined in:
- lib/drudgery/extractors/sqlite3_extractor.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #extract ⇒ Object
- #from(expression) ⇒ Object
- #group(*expressions) ⇒ Object
- #having(condition) ⇒ Object
-
#initialize(db, table) ⇒ SQLite3Extractor
constructor
A new instance of SQLite3Extractor.
- #joins(*clauses) ⇒ Object
- #order(*expressions) ⇒ Object
- #record_count ⇒ Object
- #select(*expressions) ⇒ Object
- #where(condition) ⇒ Object
Constructor Details
#initialize(db, table) ⇒ SQLite3Extractor
Returns a new instance of SQLite3Extractor.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/drudgery/extractors/sqlite3_extractor.rb', line 6 def initialize(db, table) @db = db @db.results_as_hash = true @db.type_translation = true @table = table @clauses = {} @name = "sqlite3:#{main_db_name}.#{@table}" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/drudgery/extractors/sqlite3_extractor.rb', line 4 def name @name end |
Instance Method Details
#extract ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/drudgery/extractors/sqlite3_extractor.rb', line 45 def extract index = 0 @db.execute(sql) do |row| row.reject! { |key, value| key.kind_of?(Integer) } yield [row, index] index += 1 end end |
#from(expression) ⇒ Object
21 22 23 |
# File 'lib/drudgery/extractors/sqlite3_extractor.rb', line 21 def from(expression) @clauses[:from] = expression end |
#group(*expressions) ⇒ Object
33 34 35 |
# File 'lib/drudgery/extractors/sqlite3_extractor.rb', line 33 def group(*expressions) @clauses[:group] = expressions.join(', ') end |
#having(condition) ⇒ Object
37 38 39 |
# File 'lib/drudgery/extractors/sqlite3_extractor.rb', line 37 def having(condition) @clauses[:having] = condition end |
#joins(*clauses) ⇒ Object
25 26 27 |
# File 'lib/drudgery/extractors/sqlite3_extractor.rb', line 25 def joins(*clauses) @clauses[:joins] = clauses end |
#order(*expressions) ⇒ Object
41 42 43 |
# File 'lib/drudgery/extractors/sqlite3_extractor.rb', line 41 def order(*expressions) @clauses[:order] = expressions.join(', ') end |
#record_count ⇒ Object
56 57 58 |
# File 'lib/drudgery/extractors/sqlite3_extractor.rb', line 56 def record_count @record_count ||= @db.get_first_value(count_sql) end |
#select(*expressions) ⇒ Object
17 18 19 |
# File 'lib/drudgery/extractors/sqlite3_extractor.rb', line 17 def select(*expressions) @clauses[:select] = expressions.join(', ') end |
#where(condition) ⇒ Object
29 30 31 |
# File 'lib/drudgery/extractors/sqlite3_extractor.rb', line 29 def where(condition) @clauses[:where] = condition end |