Class: Mysqlexport::Json
- Defined in:
- lib/mysqlexport/writer/json.rb
Instance Attribute Summary
Attributes inherited from Writer
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Json
constructor
A new instance of Json.
- #to_file(file) ⇒ Object
Methods inherited from Writer
#filter_path, #to_path, #to_s, #to_stdout
Constructor Details
#initialize(options = {}) ⇒ Json
Returns a new instance of Json.
5 6 7 |
# File 'lib/mysqlexport/writer/json.rb', line 5 def initialize( = {}) super(**) end |
Instance Method Details
#to_file(file) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mysqlexport/writer/json.rb', line 9 def to_file(file) first = true json_o = file.write "[" client.query(config.execute, stream: true, cache_rows: false).each do |h| next if h.nil? if first first = false else file.write "," end file.write ::MultiJson.dump(h, **json_o) end file.write "]" nil end |