lib/mysql2xxxx/json.rb in mysql2xxxx-0.0.2 vs lib/mysql2xxxx/json.rb in mysql2xxxx-0.0.3
- old
+ new
@@ -12,26 +12,25 @@
def initialize(options = {})
@properties = Properties.new options
end
- def client
- @client ||= Client.new properties
- end
-
def to_file(f)
+ @client = ::Mysql2::Client.new properties.database_config
first = true
f.write '['
- client.select_each(properties.execute) do |hsh|
+ @client.query(properties.execute).each do |hsh|
line = if first
first = false
hsh.to_json
else
',' + hsh.to_json
end
f.write line
end
f.write ']'
nil
+ ensure
+ @client.try :close
end
end
end