Class: Cequel::Metal::Statement Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cequel/metal/statement.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Builder for CQL statements. Contains a CQL string with bind substitutions and a collection of bind variables

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cql_or_prepared = '', bind_vars = []) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns cassandra type hints for bind variables.

Since:

  • 1.0.0



15
16
17
18
19
20
21
22
23
24
# File 'lib/cequel/metal/statement.rb', line 15

def initialize(cql_or_prepared='', bind_vars=[])
  cql, prepared = *case cql_or_prepared
                   when Cassandra::Statements::Prepared
                     [cql_or_prepared.cql, cql_or_prepared]
                   else
                     [cql_or_prepared.to_s, nil]
                   end

  @cql, @prepared, @bind_vars = cql, prepared, bind_vars
end

Instance Attribute Details

#bind_varsArray (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns bind variables for CQL string.

Returns:

  • (Array)

    bind variables for CQL string

Since:

  • 1.0.0



12
13
14
# File 'lib/cequel/metal/statement.rb', line 12

def bind_vars
  @bind_vars
end

Instance Method Details

#append(cql, *bind_vars) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Add a CQL fragment with optional bind variables to the end of the statement

Parameters:

  • cql (String)

    CQL fragment

  • bind_vars (Object)

    zero or more bind variables

Since:

  • 1.0.0



59
60
61
62
63
64
65
# File 'lib/cequel/metal/statement.rb', line 59

def append(cql, *bind_vars)
  unless cql.nil?
    @cql << cql
    @bind_vars.concat(bind_vars)
  end
  self
end

#argsArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns this statement as an array of arguments to Keyspace#execute (CQL string followed by bind variables).

Returns:

  • (Array)

    this statement as an array of arguments to Keyspace#execute (CQL string followed by bind variables)

Since:

  • 1.0.0



71
72
73
# File 'lib/cequel/metal/statement.rb', line 71

def args
  [cql, *bind_vars]
end

#prepare(keyspace) ⇒ Cassandra::Statements::Prepared

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns prepared version of this statement.

Returns:

  • (Cassandra::Statements::Prepared)

    prepared version of this statement

Since:

  • 1.0.0



35
36
37
# File 'lib/cequel/metal/statement.rb', line 35

def prepare(keyspace)
  @prepared ||= keyspace.client.prepare(cql)
end

#prepend(cql, *bind_vars) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Add a CQL fragment with optional bind variables to the beginning of the statement

Parameters:

  • cql (String)

    CQL fragment

  • bind_vars (Object)

    zero or more bind variables

Since:

  • 1.0.0



46
47
48
49
# File 'lib/cequel/metal/statement.rb', line 46

def prepend(cql, *bind_vars)
  @cql.prepend(cql)
  @bind_vars.unshift(*bind_vars)
end

#to_sString Also known as: cql

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns CQL statement.

Returns:

  • (String)

    CQL statement

Since:

  • 1.0.0



29
30
31
# File 'lib/cequel/metal/statement.rb', line 29

def to_s
  @cql
end