Class: Superstore::Adapters::CassandraAdapter::QueryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/superstore/adapters/cassandra_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(adapter, scope) ⇒ QueryBuilder

Returns a new instance of QueryBuilder.



8
9
10
11
# File 'lib/superstore/adapters/cassandra_adapter.rb', line 8

def initialize(adapter, scope)
  @adapter  = adapter
  @scope    = scope
end

Instance Method Details

#limit_stringObject



41
42
43
44
45
46
47
# File 'lib/superstore/adapters/cassandra_adapter.rb', line 41

def limit_string
  if @scope.limit_value
    "LIMIT #{@scope.limit_value}"
  else
    ""
  end
end

#select_stringObject



22
23
24
25
26
27
28
# File 'lib/superstore/adapters/cassandra_adapter.rb', line 22

def select_string
  if @scope.select_values.any?
    (['KEY'] | @scope.select_values) * ','
  else
    '*'
  end
end

#to_queryObject



13
14
15
16
17
18
19
20
# File 'lib/superstore/adapters/cassandra_adapter.rb', line 13

def to_query
  [
    "SELECT #{select_string} FROM #{@scope.klass.table_name}",
    @adapter.write_option_string,
    where_string,
    limit_string
  ].delete_if(&:blank?) * ' '
end

#where_stringObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/superstore/adapters/cassandra_adapter.rb', line 30

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