Module: DatastaxRails::Cql::Transactions

Extended by:
ActiveSupport::Concern
Included in:
Delete, Update
Defined in:
lib/datastax_rails/cql/transactions.rb

Overview

CQL generation for appending transactions to other queries

Instance Method Summary collapse

Instance Method Details

#if_existsObject


23
24
25
26
# File 'lib/datastax_rails/cql/transactions.rb', line 23

def if_exists
  @if_exists = true
  self
end

#if_not_existsObject


28
29
30
31
# File 'lib/datastax_rails/cql/transactions.rb', line 28

def if_not_exists
  @if_not_exists = true
  self
end

#iff(columns) ⇒ Object


18
19
20
21
# File 'lib/datastax_rails/cql/transactions.rb', line 18

def iff(columns)
  @if_conditions = columns
  self
end

#initializeObject


11
12
13
14
15
16
# File 'lib/datastax_rails/cql/transactions.rb', line 11

def initialize(*)
  @if_conditions = {}
  @if_exists = nil
  @if_not_exists = nil
  super
end

#to_cql_with_transactionsObject


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/datastax_rails/cql/transactions.rb', line 33

def to_cql_with_transactions
  stmt = to_cql_without_transactions
  if @if_not_exists
    stmt << ' IF NOT EXISTS'
  elsif @if_exists
    stmt << ' IF EXISTS'
  elsif @if_conditions.present?
    conditions = []
    @if_conditions.each do |k, v|
      conditions << "\"#{k}\" = ?"
      @values << v
    end
    stmt << " IF #{conditions.join(' AND ')}"
  end
  stmt
end