module Cassie::Statements::Statement::Assignments

Provides support for a set of CQL assignments and building the insert/update clause and argument list for a cql statement

CQL Relation terminology:

"INSERT INTO table (id, username) VALUES (?, ?);", [1, 'eprothro']

identifiers: ['id', 'username'] terms: ['?', '?'] arguments: [1, 'eprothro']

"UPDATE table SET id = ?, username = ? WHERE...;", [1, 'eprothro']

identifiers: ['id', 'username'] terms: ['?', '?'] arguments: [1, 'eprothro']

Public Class Methods

included(base) click to toggle source

@!visibility private @!parse include Mapping @!parse extend Mapping::ClassMethods

# File lib/cassie/statements/statement/assignments.rb, line 28
def self.included(base)
  base.instance_eval do
    include Mapping
  end
  base.extend ClassMethods
end

Public Instance Methods

assignments_args() click to toggle source

The enumeration of current assignments' parameters that will be used to build Assignment objects when the statement is built

# File lib/cassie/statements/statement/assignments.rb, line 72
def assignments_args
  self.class.assignments_args
end

Protected Instance Methods

build_insert_and_params() click to toggle source
# File lib/cassie/statements/statement/assignments.rb, line 93
def build_insert_and_params
  identifiers = []
  terms = []
  arguments = []

  assignments_args.each do |args|
    a = Assignment.new(self, *args)
    identifiers += Array(a.identifier)
    terms += Array(a.term)
    arguments << a.argument if a.argument?
  end

  identifiers_cql = identifiers.join(", ")
  terms_cql = terms.join(", ")

  # (indentifier, identifier)
  # VALUES
  # (term, term);
  # (identifiers_cql)
  # VALUES
  # (terms_cql);
  [identifiers_cql, terms_cql , arguments]
end
build_update_and_params() click to toggle source
# File lib/cassie/statements/statement/assignments.rb, line 78
def build_update_and_params
  arguments = []
  assignment_strings = []

  assignments_args.each do |args|
    a = Assignment.new(self, *args)
    assignment_strings += Array(a.to_update_cql)
    arguments << a.argument if a.argument?
  end

  cql = assignment_strings.join(', ')

  [cql , arguments]
end