Class: Cassava::StatementBuilder
- Inherits:
-
Object
- Object
- Cassava::StatementBuilder
- Defined in:
- lib/cassava/client.rb
Constant Summary collapse
- CLAUSE_ORDERING =
{ :main => 0, :from => 1, :where => 2, :order => 3, :limit => 4, :allow_filtering => 5 }
Instance Attribute Summary collapse
-
#clauses ⇒ Object
readonly
Returns the value of attribute clauses.
-
#executor ⇒ Object
readonly
Returns the value of attribute executor.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
-
#allow_filtering ⇒ StatementBuilder
Allow filtering for this query.
-
#count ⇒ StatementBuilder
Return the count of objects rather than the objects themselves.
- #delete(table, columns = nil) ⇒ StatementBuilder
-
#execute(opts = {}) ⇒ Object
Execute the statement synchronously.
-
#execute_async(opts = {}) ⇒ Object
Execute the statement asynchronously.
-
#initialize(executor, clauses = {}) ⇒ StatementBuilder
constructor
A new instance of StatementBuilder.
- #limit(n) ⇒ StatementBuilder
- #order(clustering_column, direction = :asc) ⇒ StatementBuilder
- #select(table, columns = nil) ⇒ StatementBuilder
-
#statement ⇒ String
The CQL statement that this StatementBuilder represents.
-
#where(*args) ⇒ StatementBuilder
Condition the query based on a condition Provide either a String and a list of arguments, or a hash.
Constructor Details
#initialize(executor, clauses = {}) ⇒ StatementBuilder
Returns a new instance of StatementBuilder.
74 75 76 77 78 |
# File 'lib/cassava/client.rb', line 74 def initialize(executor, clauses = {}) @executor = executor @table = table @clauses = clauses end |
Instance Attribute Details
#clauses ⇒ Object (readonly)
Returns the value of attribute clauses.
63 64 65 |
# File 'lib/cassava/client.rb', line 63 def clauses @clauses end |
#executor ⇒ Object (readonly)
Returns the value of attribute executor.
63 64 65 |
# File 'lib/cassava/client.rb', line 63 def executor @executor end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
63 64 65 |
# File 'lib/cassava/client.rb', line 63 def table @table end |
Instance Method Details
#allow_filtering ⇒ StatementBuilder
Allow filtering for this query
123 124 125 |
# File 'lib/cassava/client.rb', line 123 def allow_filtering add_clause('ALLOW FILTERING', :allow_filtering) end |
#count ⇒ StatementBuilder
Return the count of objects rather than the objects themselves
142 143 144 |
# File 'lib/cassava/client.rb', line 142 def count add_clause(clauses[:main].count, :main) end |
#delete(table, columns = nil) ⇒ StatementBuilder
104 105 106 |
# File 'lib/cassava/client.rb', line 104 def delete(table, columns = nil) add_clause(DeleteClause.new(table, columns), :main) end |
#execute(opts = {}) ⇒ Object
Execute the statement synchronously
82 83 84 85 |
# File 'lib/cassava/client.rb', line 82 def execute(opts = {}) = opts.dup.merge(:arguments => prepared_arguments) executor.execute(prepared_statement, ) end |
#execute_async(opts = {}) ⇒ Object
Execute the statement asynchronously
89 90 91 92 |
# File 'lib/cassava/client.rb', line 89 def execute_async(opts = {}) = opts.dup.merge(:arguments => prepared_arguments) executor.execute_async(prepared_statement, ) end |
#limit(n) ⇒ StatementBuilder
136 137 138 |
# File 'lib/cassava/client.rb', line 136 def limit(n) add_clause("LIMIT #{n.to_i}", :limit) end |
#order(clustering_column, direction = :asc) ⇒ StatementBuilder
130 131 132 |
# File 'lib/cassava/client.rb', line 130 def order(clustering_column, direction = :asc) add_clause("ORDER BY #{clustering_column.to_s} #{direction.to_s}", :order) end |
#select(table, columns = nil) ⇒ StatementBuilder
97 98 99 |
# File 'lib/cassava/client.rb', line 97 def select(table, columns = nil) add_clause(SelectClause.new(table, columns), :main) end |
#statement ⇒ String
Returns the CQL statement that this StatementBuilder represents.
147 148 149 |
# File 'lib/cassava/client.rb', line 147 def statement clauses.sort_by { |s| CLAUSE_ORDERING[s[0]] }.map { |s| s[1] }.join(' ') end |
#where(*args) ⇒ StatementBuilder
Condition the query based on a condition Provide either a String and a list of arguments, or a hash.
116 117 118 119 |
# File 'lib/cassava/client.rb', line 116 def where(*args) clause = clauses[:where] || WhereClause.new([], []) add_clause(clause.where(*args), :where) end |