Class: ThinkingSphinx::Connection::MRI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address, port, options) ⇒ MRI

Returns a new instance of MRI.



58
59
60
61
62
63
64
# File 'lib/thinking_sphinx/connection.rb', line 58

def initialize(address, port, options)
  @client = Mysql2::Client.new({
    :host  => address,
    :port  => port,
    :flags => Mysql2::Client::MULTI_STATEMENTS
  }.merge(options))
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



56
57
58
# File 'lib/thinking_sphinx/connection.rb', line 56

def client
  @client
end

Instance Method Details

#closeObject



66
67
68
# File 'lib/thinking_sphinx/connection.rb', line 66

def close
  client.close
end

#execute(statement) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/thinking_sphinx/connection.rb', line 70

def execute(statement)
  client.query statement
rescue => error
  wrapper           = ThinkingSphinx::QueryExecutionError.new error.message
  wrapper.statement = statement
  raise wrapper
end

#query(statement) ⇒ Object



78
79
80
# File 'lib/thinking_sphinx/connection.rb', line 78

def query(statement)
  client.query statement
end

#query_all(*statements) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/thinking_sphinx/connection.rb', line 82

def query_all(*statements)
  results  = [client.query(statements.join('; '))]
  results << client.store_result while client.next_result
  results
rescue => error
  wrapper           = ThinkingSphinx::QueryExecutionError.new error.message
  wrapper.statement = statements.join('; ')
  raise wrapper
end