Class: Cassanity::ArgumentGenerators::ColumnFamilySelect

Inherits:
Object
  • Object
show all
Defined in:
lib/cassanity/argument_generators/column_family_select.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ColumnFamilySelect

Internal



11
12
13
14
15
16
# File 'lib/cassanity/argument_generators/column_family_select.rb', line 11

def initialize(args = {})
  @using_clause = args.fetch(:using_clause) { UsingClause.new }
  @where_clause = args.fetch(:where_clause) { WhereClause.new }
  @order_clause = args.fetch(:order_clause) { OrderClause.new }
  @limit_clause = args.fetch(:limit_clause) { LimitClause.new }
end

Instance Method Details

#call(args = {}) ⇒ Object

Internal



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cassanity/argument_generators/column_family_select.rb', line 19

def call(args = {})
  select = Array(args.fetch(:select, '*'))
  name   = args.fetch(:name)
  where  = args[:where]
  using  = args[:using]
  order  = args[:order]
  limit  = args[:limit]

  variables = []

  if (keyspace_name = args[:keyspace_name])
    name = "#{keyspace_name}.#{name}"
  end

  cql = "SELECT #{select.join(', ')} FROM #{name}"

  using_cql, *using_variables = @using_clause.call(using: using)
  cql << using_cql
  variables.concat(using_variables)

  where_cql, *where_variables = @where_clause.call(where: where)
  cql << where_cql
  variables.concat(where_variables)

  order_cql, *order_variables = @order_clause.call(order: order)
  cql << order_cql
  variables.concat(order_variables)

  limit_cql, *limit_variables = @limit_clause.call(limit: limit)
  cql << limit_cql
  variables.concat(limit_variables)

  [cql, *variables]
end