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

- (MRI) initialize(address, port, options)



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

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

Instance Attribute Details

- (Object) client (readonly)

Returns the value of attribute client



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

def client
  @client
end

Instance Method Details

- (Object) close



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

def close
  client.close
end

- (Object) execute(statement)



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

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

- (Object) query(statement)



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

def query(statement)
  client.query statement
end

- (Object) query_all(*statements)



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

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