Class: Mysqlknife::MySQL

Inherits:
Object
  • Object
show all
Defined in:
lib/mysqlknife/mysql.rb

Instance Method Summary collapse

Constructor Details

#initializeMySQL

Returns a new instance of MySQL.



5
6
7
# File 'lib/mysqlknife/mysql.rb', line 5

def initialize
  @cnf = Configs.instance
end

Instance Method Details

#execute(sql) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mysqlknife/mysql.rb', line 9

def execute(sql)
  conn = Mysql2::Client.new(host: @cnf.mysql_host,
                            port: @cnf.mysql_port,
                            username: @cnf.mysql_username,
                            password: @cnf.mysql_password,
                            database: @cnf.mysql_database)

  Mysqlknife::Log.new.sql(sql)

  return conn.query(sql)
rescue Mysql2::Error => error
  Mysqlknife::Log.new.sql_error(error, sql)
  exit(1)
end