class Cassandra::Statements::Simple
Attributes
@return [String] original cql used to prepare this statement
@return [Array<Object>] a list of positional parameters for the cql
@private
@private
Public Class Methods
@param cql [String] a cql statement @param params [Array, Hash] (nil) positional or named arguments
for the query
@param type_hints [Array, Hash] (nil) positional or named types
to override type guessing for the query
@param idempotent [Boolean] (false) whether this statement can be
safely retries on timeouts
@note Positional arguments for simple statements are only supported
starting with Apache Cassandra 2.0 and above.
@note Named arguments for simple statements are only supported
starting with Apache Cassandra 2.1 and above.
@raise [ArgumentError] if cql statement given is not a String
# File lib/cassandra/statements/simple.rb 50 def initialize(cql, params = nil, type_hints = nil, idempotent = false) 51 Util.assert_instance_of(::String, cql) do 52 "cql must be a string, #{cql.inspect} given" 53 end 54 55 params ||= EMPTY_LIST 56 57 if params.is_a?(::Hash) 58 params_names = [] 59 params = params.each_with_object([]) do |(name, value), collector| 60 params_names << name 61 collector << value 62 end 63 if type_hints && !type_hints.empty? 64 Util.assert_instance_of(::Hash, type_hints) do 65 'type_hints must be a Hash when using named params' 66 end 67 end 68 else 69 Util.assert_instance_of(::Array, params) do 70 "params must be an Array or a Hash, #{params.inspect} given" 71 end 72 params_names = EMPTY_LIST 73 end 74 75 type_hints ||= EMPTY_LIST 76 77 if type_hints.is_a?(::Hash) 78 type_hints = params_names.map {|name| type_hints[name] } 79 else 80 Util.assert_instance_of(::Array, type_hints) do 81 "type_hints must be an Array or a Hash, #{type_hints.inspect} given" 82 end 83 end 84 85 @cql = cql 86 @params = params 87 @params_types = params.each_with_index.map do |value, index| 88 (!type_hints.empty? && type_hints[index] && type_hints[index].is_a?(Type)) ? 89 type_hints[index] : 90 Util.guess_type(value) 91 end 92 @params_names = params_names 93 @idempotent = idempotent 94 end
Public Instance Methods
@private
# File lib/cassandra/statements/simple.rb 97 def accept(client, options) 98 client.query(self, options) 99 end
@param other [Object, Cassandra::Statements::Simple] object to compare @return [Boolean] whether the statements are equal
# File lib/cassandra/statements/simple.rb 109 def eql?(other) 110 other.is_a?(Simple) && 111 @cql == other.cql && 112 @params == other.params 113 end
@return [String] a CLI-friendly simple statement representation
# File lib/cassandra/statements/simple.rb 102 def inspect 103 "#<#{self.class.name}:0x#{object_id.to_s(16)} @cql=#{@cql.inspect} " \ 104 "@params=#{@params.inspect}>" 105 end