Class: Oedipus::QueryBuilder
- Inherits:
-
Object
- Object
- Oedipus::QueryBuilder
- Defined in:
- lib/oedipus/query_builder.rb
Overview
Constructs SphinxQL queries from the internal Hash format.
Instance Method Summary collapse
-
#delete(id) ⇒ String
Build a SphinxQL query to delete the record identified by
id
. -
#initialize(index_name) ⇒ QueryBuilder
constructor
Initialize a new QueryBuilder for
index_name
. -
#insert(id, attributes) ⇒ String
Build a SphinxQL query to insert the record identified by
id
with the given attributes. -
#replace(id, attributes) ⇒ String
Build a SphinxQL query to replace the record identified by
id
with the given attributes. -
#select(query, filters) ⇒ String
Build a SphinxQL query for the fulltext search
query
and filters infilters
. -
#update(id, attributes) ⇒ String
Build a SphinxQL query to update the record identified by
id
with the given attributes.
Constructor Details
#initialize(index_name) ⇒ QueryBuilder
Initialize a new QueryBuilder for index_name
.
17 18 19 |
# File 'lib/oedipus/query_builder.rb', line 17 def initialize(index_name) @index_name = index_name end |
Instance Method Details
#delete(id) ⇒ String
Build a SphinxQL query to delete the record identified by id
.
101 102 103 |
# File 'lib/oedipus/query_builder.rb', line 101 def delete(id) ["DELETE FROM #{@index_name} WHERE id = ?", id] end |
#insert(id, attributes) ⇒ String
Build a SphinxQL query to insert the record identified by id
with the given attributes.
54 55 56 |
# File 'lib/oedipus/query_builder.rb', line 54 def insert(id, attributes) into("INSERT", id, attributes) end |
#replace(id, attributes) ⇒ String
Build a SphinxQL query to replace the record identified by id
with the given attributes.
90 91 92 |
# File 'lib/oedipus/query_builder.rb', line 90 def replace(id, attributes) into("REPLACE", id, attributes) end |
#select(query, filters) ⇒ String
Build a SphinxQL query for the fulltext search query
and filters in filters
.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/oedipus/query_builder.rb', line 31 def select(query, filters) where, *bind_values = conditions(query, filters) [ [ from(filters), where, order_by(filters), limits(filters) ].join(" "), *bind_values ] end |
#update(id, attributes) ⇒ String
Build a SphinxQL query to update the record identified by id
with the given attributes.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/oedipus/query_builder.rb', line 68 def update(id, attributes) set_attrs, *bind_values = update_attributes(attributes) [ [ "UPDATE #{@index_name} SET", set_attrs, "WHERE id = ?" ].join(" "), *bind_values.push(id) ] end |