Class: CassandraObject::Adapters::HstoreAdapter::QueryBuilder
- Inherits:
-
Object
- Object
- CassandraObject::Adapters::HstoreAdapter::QueryBuilder
- Defined in:
- lib/cassandra_object/adapters/hstore_adapter.rb
Instance Method Summary collapse
-
#initialize(adapter, scope) ⇒ QueryBuilder
constructor
A new instance of QueryBuilder.
- #limit_string ⇒ Object
- #order_string ⇒ Object
- #select_string ⇒ Object
- #to_query ⇒ Object
- #where_string ⇒ Object
Constructor Details
#initialize(adapter, scope) ⇒ QueryBuilder
Returns a new instance of QueryBuilder.
5 6 7 8 |
# File 'lib/cassandra_object/adapters/hstore_adapter.rb', line 5 def initialize(adapter, scope) @adapter = adapter @scope = scope end |
Instance Method Details
#limit_string ⇒ Object
45 46 47 48 49 |
# File 'lib/cassandra_object/adapters/hstore_adapter.rb', line 45 def limit_string if @scope.limit_value "LIMIT #{@scope.limit_value}" end end |
#order_string ⇒ Object
38 39 40 41 42 43 |
# File 'lib/cassandra_object/adapters/hstore_adapter.rb', line 38 def order_string if @scope.id_values.many? id_orders = @scope.id_values.map { |id| "ID=#{@adapter.quote(id)} DESC" }.join(',') "ORDER BY #{id_orders}" end end |
#select_string ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/cassandra_object/adapters/hstore_adapter.rb', line 19 def select_string if @scope.select_values.any? "id, slice(attribute_store, #{@adapter.fields_to_postgres_array(@scope.select_values)}) as attribute_store" else '*' end end |
#to_query ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/cassandra_object/adapters/hstore_adapter.rb', line 10 def to_query [ "SELECT #{select_string} FROM #{@scope.klass.column_family}", where_string, order_string, limit_string, ].delete_if(&:blank?) * ' ' end |
#where_string ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cassandra_object/adapters/hstore_adapter.rb', line 27 def where_string wheres = @scope.where_values.dup if @scope.id_values.any? wheres << @adapter.create_ids_where_clause(@scope.id_values) end if wheres.any? "WHERE #{wheres * ' AND '}" end end |