Module: DBA::LDJSON
- Defined in:
- lib/dba/ldjson.rb
Class Method Summary collapse
Class Method Details
.dump(database, table_name, path) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/dba/ldjson.rb', line 5 def self.dump(database, table_name, path) File.open(path, 'w+') do |io| database[table_name].each do |row| io.puts ::JSON.generate(row.compact) end end end |
.load(path, database, table_name) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/dba/ldjson.rb', line 13 def self.load(path, database, table_name) dataset = database[table_name] database.transaction do File.readlines(path).each do |line| dataset.insert(::JSON.parse(line)) end end end |