Class: Oculus::Connection::Mysql2

Inherits:
Object
  • Object
show all
Defined in:
lib/oculus/connection/mysql2.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mysql2

Returns a new instance of Mysql2.



6
7
8
# File 'lib/oculus/connection/mysql2.rb', line 6

def initialize(options = {})
  @connection = ::Mysql2::Client.new(options)
end

Instance Method Details

#execute(sql) ⇒ Object



10
11
12
13
14
15
# File 'lib/oculus/connection/mysql2.rb', line 10

def execute(sql)
  results = @connection.query(sql)
  [results.fields] + results.map(&:values) if results
rescue ::Mysql2::Error => e
  raise Connection::Error.new(e.message)
end

#kill(id) ⇒ Object



17
18
19
# File 'lib/oculus/connection/mysql2.rb', line 17

def kill(id)
  execute("KILL QUERY #{id}")
end

#thread_idObject



21
22
23
# File 'lib/oculus/connection/mysql2.rb', line 21

def thread_id
  @connection.thread_id
end