Class: CSVPP::SqliteImporter
- Inherits:
-
Object
- Object
- CSVPP::SqliteImporter
- Defined in:
- lib/csvpp/sqlite_importer.rb
Overview
Imports data into an Sqlite database.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Instance Method Summary collapse
- #import(input) ⇒ Object
-
#initialize(format:, db_path:) ⇒ SqliteImporter
constructor
A new instance of SqliteImporter.
Constructor Details
#initialize(format:, db_path:) ⇒ SqliteImporter
Returns a new instance of SqliteImporter.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/csvpp/sqlite_importer.rb', line 12 def initialize(format:, db_path:) @format = format @db = Sequel.sqlite(db_path) @db.drop_table? :data @db.create_table :data do Int :line_number format.var_names.each do |var| type = format.type(var) if type.start_with?('array') type = 'String' else type.capitalize end send(type, var) end end @data = @db[:data] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/csvpp/sqlite_importer.rb', line 8 def data @data end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
8 9 10 |
# File 'lib/csvpp/sqlite_importer.rb', line 8 def db @db end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
8 9 10 |
# File 'lib/csvpp/sqlite_importer.rb', line 8 def format @format end |