Class: Cassandra::Statements::Simple

Inherits:
Object
  • Object
show all
Includes:
Cassandra::Statement
Defined in:
lib/cassandra/statements/simple.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cql, params = nil) ⇒ Simple

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.

Returns a new instance of Simple.

Parameters:

  • cql (String)

    a cql statement

  • params (Array) (defaults to: nil)

    (nil) positional arguments for the query

Raises:

  • (ArgumentError)

    if cql statement given is not a String



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cassandra/statements/simple.rb', line 45

def initialize(cql, params = nil)
  Util.assert_instance_of(::String, cql) { "cql must be a string, #{cql.inspect} given" }

  params ||= EMPTY_LIST

  if params.is_a?(::Hash)
    params_names = []
    params = params.each_with_object([]) do |(name, value), params|
      params_names << name
      params       << value
    end
  else
    Util.assert_instance_of(::Array, params) { "params must be an Array or a Hash, #{params.inspect} given" }
    params_names = EMPTY_LIST
  end

  @cql          = cql
  @params       = params
  @params_types = params.map {|value| Util.guess_type(value)}
  @params_names = params_names
end

Instance Attribute Details

#cqlString (readonly)

Returns original cql used to prepare this statement.

Returns:

  • (String)

    original cql used to prepare this statement



25
26
27
# File 'lib/cassandra/statements/simple.rb', line 25

def cql
  @cql
end

#paramsArray<Object> (readonly)

Returns a list of positional parameters for the cql.

Returns:

  • (Array<Object>)

    a list of positional parameters for the cql



27
28
29
# File 'lib/cassandra/statements/simple.rb', line 27

def params
  @params
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns whether the statements are equal.

Parameters:

Returns:

  • (Boolean)

    whether the statements are equal



74
75
76
77
78
# File 'lib/cassandra/statements/simple.rb', line 74

def eql?(other)
  other.is_a?(Simple) &&
    @cql == other.cql &&
    @params == other.params
end

#inspectString

Returns a CLI-friendly simple statement representation.

Returns:

  • (String)

    a CLI-friendly simple statement representation



68
69
70
# File 'lib/cassandra/statements/simple.rb', line 68

def inspect
  "#<#{self.class.name}:0x#{self.object_id.to_s(16)} @cql=#{@cql.inspect} @params=#{@params.inspect}>"
end