module Cassie::Statements::Statement

Include Statement to provide support for a `statement` method returning a `Cassandra::Statements::Simple` statement with positional arguments.

`type` and `table` attributes are also added, providing an extension interface for building cql and bindings for different statement types.

Attributes

table[RW]
type[RW]

Public Class Methods

included(base) click to toggle source

@!visibility private @!parse include Preparation @!parse extend Preparation::ClassMethods @!parse include TypeHinting @!parse include TypeHinting::ClassMethods @!parse include Idempotency @!parse include Idempotency::ClassMethods

# File lib/cassie/statements/statement.rb, line 26
def self.included(base)
  base.instance_eval do
    include Preparation
    include TypeHinting
    include Idempotency

    class << self
      attr_accessor :table
      attr_accessor :type
    end
  end
end

Public Instance Methods

cql() click to toggle source

The CQL string portion for the statment @!parse attr_reader :cql @example

statement.cql
#=> "SELECT * FROM table WHERE first=? AND middle=? and last=?"
# File lib/cassie/statements/statement.rb, line 76
def cql
  return @cql if defined?(@cql)
  ""
end
logger() click to toggle source
# File lib/cassie/statements/statement.rb, line 67
def logger
  Cassie::Statements.logger
end
params() click to toggle source

The positional values portion for the statment @example

statement.params
#=> ['evan', 'thomas', 'prothro']

@!parse attr_reader :params

# File lib/cassie/statements/statement.rb, line 86
def params
  return @params if defined?(@params)
  nil
end
statement() click to toggle source

A bound statment with type hint and idempotent options, ready for execution ready for execution with a [Cassandra::Session] @return [Cassandra::Statement]

# File lib/cassie/statements/statement.rb, line 45
def statement
  Cassandra::Statements::Simple.new(*build_cql_and_params, type_hints, idempotent?)
end
table() click to toggle source
# File lib/cassie/statements/statement.rb, line 39
def table
  self.class.table
end
to_cql() click to toggle source

A CQL string with inline parameters, representing the current statement as it would be executed in a CQL shell

@note This CQL string does not include execution options like type hinting,

idempotency, consistency level, etc -- just the raw CQL instruction and values.

@return [String]

@example

statement.to_cql
#=> "SELECT * FROM table WHERE first='evan' AND middle='thomas' and last='prothro"
# File lib/cassie/statements/statement.rb, line 59
def to_cql
  if statement.respond_to?(:cql) && statement.respond_to?(:params)
    Cassie::Support::StatementParser.new(statement).to_cql
  else
    statement.to_s
  end
end

Protected Instance Methods

build_cql_and_params() click to toggle source
# File lib/cassie/statements/statement.rb, line 93
def build_cql_and_params
  if self.class.type
    send "build_#{self.class.type}_cql_and_params"
  end

  [cql, params]
end

Private Instance Methods

source_eval(value, src=self) click to toggle source
# File lib/cassie/statements/statement.rb, line 103
def source_eval(value, src=self)
  case value
  when Symbol
    src.send(value)
  else
    value
  end
end