Class: Oedipus::Connection
- Inherits:
-
Object
- Object
- Oedipus::Connection
- Defined in:
- lib/oedipus/connection.rb,
lib/oedipus/connection/pool.rb,
lib/oedipus/connection/registry.rb
Overview
Provides an interface for talking to SphinxQL.
Currently this class wraps a native mysql extension.
Defined Under Namespace
Modules: Registry Classes: Pool
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#[](index_name) ⇒ Index
(also: #index)
Acess a specific index for querying.
-
#close ⇒ Object
Disconnect from the remote host.
-
#execute(sql, *bind_values) ⇒ Fixnum
Execute a non-read query.
-
#initialize(options) ⇒ Connection
constructor
Instantiate a new Connection to a SphinxQL host.
-
#multi_query(sql, *bind_values) ⇒ Array
Execute one or more queries in a batch.
-
#query(sql, *bind_values) ⇒ Array
Execute a single read query.
Constructor Details
#initialize(options) ⇒ Connection
Instantiate a new Connection to a SphinxQL host.
The connection will be established on initialization.
The underlying implementation uses a thread-safe connection pool.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/oedipus/connection.rb', line 28 def initialize() @options = if .kind_of?(String) Hash[ [:host, :port].zip(.split(":")) ] else .dup end.tap { |o| o[:port] = o[:port].to_i } @pool = Pool.new( host: @options[:host], port: @options[:port], size: @options.fetch(:pool_size, 8), ttl: 60 ) assert_valid_pool unless @options[:verify] == false end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/oedipus/connection.rb', line 15 def @options end |
Instance Method Details
#[](index_name) ⇒ Index Also known as: index
Acess a specific index for querying.
53 54 55 |
# File 'lib/oedipus/connection.rb', line 53 def [](index_name) Index.new(index_name, self) end |
#close ⇒ Object
Disconnect from the remote host.
There is no need to explicitly re-connect after invoking this; connections are re-established as needed.
114 115 116 |
# File 'lib/oedipus/connection.rb', line 114 def close @pool.dispose end |
#execute(sql, *bind_values) ⇒ Fixnum
Execute a non-read query.
Note that SphinxQL does not support prepared statements.
106 107 108 |
# File 'lib/oedipus/connection.rb', line 106 def execute(sql, *bind_values) @pool.acquire { |conn| conn.execute(sql, *bind_values) } end |
#multi_query(sql, *bind_values) ⇒ Array
Execute one or more queries in a batch.
Queries should be separated by semicolons. Results are returned in a 2-dimensional array.
Note that SphinxQL does not support prepared statements.
74 75 76 |
# File 'lib/oedipus/connection.rb', line 74 def multi_query(sql, *bind_values) @pool.acquire { |conn| conn.query(sql, *bind_values) } end |
#query(sql, *bind_values) ⇒ Array
Execute a single read query.
Note that SphinxQL does not support prepared statements.
90 91 92 |
# File 'lib/oedipus/connection.rb', line 90 def query(sql, *bind_values) @pool.acquire { |conn| conn.query(sql, *bind_values).first } end |