Class: NetSystem::MysqlClient

Inherits:
Client show all
Defined in:
lib/net_system/subsystems/database/clients/mysql_client.rb

Instance Attribute Summary collapse

Attributes inherited from Liza::Controller

#menv

Instance Method Summary collapse

Methods inherited from Liza::Controller

#`, `, attr_accessor, attr_reader, attr_writer, #attrs, box, #box, call, color, division, division!, division?, inherited, menv_accessor, menv_reader, menv_writer, on_connected, panel, #panel, plural, require, requirements, sh, #sh, singular, subsystem, subsystem!, subsystem?, subsystem_token, token

Methods inherited from Liza::Unit

_erbs_for, #add, add, cl, #cl, class_methods_defined, const_added, const_missing, constants_defined, define_error, descendants_select, division, erbs_available, erbs_defined, erbs_for, errors, #fetch, fetch, get, #get, instance_methods_defined, log, #log, log?, #log?, #log_array, log_array, log_hash, #log_hash, #log_level, log_level, #log_level?, log_level?, log_levels, #log_levels, #log_render_convert, #log_render_format, #log_render_in, #log_render_out, method_added, methods_defined, namespace, part, raise_error, #raise_error, reload!, #reload!, #render, #render!, #render_stack, renderable_formats_for, renderable_names, section, sections, #set, set, #settings, settings, singleton_method_added, sleep, #sleep, stick, #stick, sticks, #sticks, subclasses_select, subunits, system, #system, system?, test_class, time_diff, #time_diff

Constructor Details

#initialize(hash = {}) ⇒ MysqlClient



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/net_system/subsystems/database/clients/mysql_client.rb', line 6

def initialize hash={}
  self.class.call({})
  t = Time.now
  hash = NetBox[:client].get(:mysql_hash) if hash.empty?

  # "localhost" would force a socket connection
  hash[:host] = "127.0.0.1" if hash[:host] == "localhost"

  @conn = Mysql2::Client.new(hash)
ensure
  log "#{t.diff}s | Connecting to #{hash}"
end

Instance Attribute Details

#conn ⇒ Object (readonly)

Returns the value of attribute conn.



19
20
21
# File 'lib/net_system/subsystems/database/clients/mysql_client.rb', line 19

def conn
  @conn
end

Instance Method Details

#call(sql, *args) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/net_system/subsystems/database/clients/mysql_client.rb', line 21

def call sql, *args
  t = Time.now
  result = @conn.query sql, *args

  result
ensure
  log "#{t.diff}s | #{sql} | #{args}"
end

#now ⇒ Object



30
31
32
# File 'lib/net_system/subsystems/database/clients/mysql_client.rb', line 30

def now
  call "SELECT UTC_TIMESTAMP()"
end