Class: DDG::Adapter::MySQL

Inherits:
Base
  • Object
show all
Defined in:
lib/ddg/adapter/mysql.rb

Instance Method Summary collapse

Methods inherited from Base

#tables_with_foreign_keys

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