class CSVPP::SqliteImporter
Imports data into an Sqlite database.
Attributes
data[R]
db[R]
format[R]
Public Class Methods
new(format:, db_path:)
click to toggle source
@param format [Format] @param db_path [String]
# 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
Public Instance Methods
import(input)
click to toggle source
@param input [String] input string
# File lib/csvpp/sqlite_importer.rb, line 37 def import(input) Parser.parse_str( input: input, format: format, convert_type: false ) do |attr| data.insert(attr) end end