Class: Drudgery::Loaders::SQLite3Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/drudgery/loaders/sqlite3_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, table) ⇒ SQLite3Loader

Returns a new instance of SQLite3Loader.



6
7
8
9
10
11
12
13
14
# File 'lib/drudgery/loaders/sqlite3_loader.rb', line 6

def initialize(db, table)
  @db = db
  @db.results_as_hash = true
  @db.type_translation = true

  @table = table

  @name = "sqlite3:#{main_db_name}.#{@table}"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/drudgery/loaders/sqlite3_loader.rb', line 4

def name
  @name
end

Instance Method Details

#load(records) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/drudgery/loaders/sqlite3_loader.rb', line 16

def load(records)
  columns = records.first.keys

  @db.transaction do |db|
    records.each do |record|
      db.execute(sql(columns), columns.map { |column| record[column] })
    end
  end
end