Class: DDG::Adapter::MySQL
Instance Method Summary collapse
-
#initialize(config) ⇒ MySQL
constructor
A new instance of MySQL.
- #select(sql) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(config) ⇒ MySQL
Returns a new instance of MySQL.
10 11 12 13 14 15 16 17 18 |
# File 'lib/ddg/adapter/mysql.rb', line 10 def initialize(config) @db = Mysql2::Client.new( host: config[:host], port: config[:port], username: config[:user], password: config[:password], database: config[:database] ) end |
Instance Method Details
#select(sql) ⇒ Object
20 21 22 23 24 |
# File 'lib/ddg/adapter/mysql.rb', line 20 def select(sql) @db.query(sql).to_a.map do |row| JSON.parse(row.to_json, symbolize_names: true) end end |