Class: Cassanity::ArgumentGenerators::ColumnFamilyUpdate
- Inherits:
-
Object
- Object
- Cassanity::ArgumentGenerators::ColumnFamilyUpdate
- Defined in:
- lib/cassanity/argument_generators/column_family_update.rb
Instance Method Summary collapse
-
#call(args = {}) ⇒ Object
Internal: Converts a Hash of arguments to CQL with bound variables.
-
#initialize(args = {}) ⇒ ColumnFamilyUpdate
constructor
Internal.
Constructor Details
#initialize(args = {}) ⇒ ColumnFamilyUpdate
Internal
10 11 12 13 14 |
# File 'lib/cassanity/argument_generators/column_family_update.rb', line 10 def initialize(args = {}) @using_clause = args.fetch(:using_clause) { UsingClause.new } @set_clause = args.fetch(:set_clause) { SetClause.new } @where_clause = args.fetch(:where_clause) { WhereClause.new } end |
Instance Method Details
#call(args = {}) ⇒ Object
Internal: Converts a Hash of arguments to CQL with bound variables.
args - The Hash of arguments to use.
:name - The String name of the column family
:set - The Hash of data to actually update
:where - The Hash of options to use to filter the update
:using - The Hash of options for the query ie: consistency, ttl,
and timestamp (optional).
Examples
call({
name: 'apps',
set: {
name: 'GitHub',
},
where: {
:id => '1',
}
})
Returns Array where first element is CQL string and the rest are
bound values.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cassanity/argument_generators/column_family_update.rb', line 39 def call(args = {}) name = args.fetch(:name) set = args.fetch(:set) where = args.fetch(:where) using = args[:using] || {} variables = [] if (keyspace_name = args[:keyspace_name]) name = "#{keyspace_name}.#{name}" end cql = "UPDATE #{name}" using_cql, *using_variables = @using_clause.call(using: using) cql << using_cql variables.concat(using_variables) set_cql, *set_variables = @set_clause.call(set: set) cql << set_cql variables.concat(set_variables) where_cql, *where_variables = @where_clause.call(where: where) cql << where_cql variables.concat(where_variables) [cql, *variables] end |