Class: Oedipus::Connection
- Inherits:
-
Object
- Object
- Oedipus::Connection
- Defined in:
- lib/oedipus/connection.rb,
lib/oedipus/connection/pool.rb
Overview
Provides an interface for talking to SphinxQL.
Currently this class wraps a native mysql extension.
Defined Under Namespace
Classes: Pool
Instance Method Summary collapse
-
#[](index_name) ⇒ Index
Acess a specific index for querying.
-
#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.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/oedipus/connection.rb', line 26 def initialize() = .kind_of?(String) ? Hash[ [:host, :port].zip(.split(":")) ] : @pool = Pool.new( host: [:host], port: [:port].to_i, size: .fetch(:pool_size, 8), ttl: 60 ) assert_valid_pool end |
Instance Method Details
#[](index_name) ⇒ Index
Acess a specific index for querying.
48 49 50 |
# File 'lib/oedipus/connection.rb', line 48 def [](index_name) Index.new(index_name, self) end |
#execute(sql, *bind_values) ⇒ Fixnum
Execute a non-read query.
Note that SphinxQL does not support prepared statements.
99 100 101 |
# File 'lib/oedipus/connection.rb', line 99 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.
67 68 69 |
# File 'lib/oedipus/connection.rb', line 67 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.
83 84 85 |
# File 'lib/oedipus/connection.rb', line 83 def query(sql, *bind_values) @pool.acquire { |conn| conn.query(sql, *bind_values).first } end |