Class: RtSphinx::Query
- Inherits:
-
Object
- Object
- RtSphinx::Query
- Defined in:
- lib/rt_sphinx/query.rb
Instance Method Summary collapse
-
#initialize ⇒ Query
constructor
A new instance of Query.
- #insert(*values) ⇒ Object
- #select(clause) ⇒ Object
Constructor Details
#initialize ⇒ Query
Returns a new instance of Query.
6 7 8 |
# File 'lib/rt_sphinx/query.rb', line 6 def initialize @connection = RtSphinx::Connection.instance end |
Instance Method Details
#insert(*values) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/rt_sphinx/query.rb', line 15 def insert(*values) item_id = rand(10_000)*rand(9_888) values_str = values.map{|v| "'#{v}'"}.join(', ') insert_sql = "INSERT INTO rt_logs (id, timestamp, message, logjson) VALUES (#{item_id}, #{values_str})" @connection.execute_sql(insert_sql, 'insert') end |
#select(clause) ⇒ Object
10 11 12 13 |
# File 'lib/rt_sphinx/query.rb', line 10 def select(clause) select_sql = "SELECT * FROM rt_logs WHERE #{clause}" @connection.execute_sql(select_sql, 'select') end |