Class: DatastaxRails::Cql::Delete

Inherits:
Base show all
Includes:
Transactions
Defined in:
lib/datastax_rails/cql/delete.rb

Overview

Generates CQL to delete a record from Cassandra

Instance Method Summary collapse

Methods included from Transactions

#if_exists, #if_not_exists, #iff, #to_cql_with_transactions

Methods inherited from Base

#execute, #using

Constructor Details

#initialize(klass, key) ⇒ Delete

Returns a new instance of Delete.



5
6
7
8
9
10
11
# File 'lib/datastax_rails/cql/delete.rb', line 5

def initialize(klass, key)
  @klass = klass
  @key = key
  @timestamp = nil
  @columns = []
  super
end

Instance Method Details

#columns(columns) ⇒ Object



13
14
15
16
# File 'lib/datastax_rails/cql/delete.rb', line 13

def columns(columns)
  @columns = columns
  self
end

#timestamp(timestamp) ⇒ Object



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

def timestamp(timestamp)
  @timestamp = timestamp
  self
end

#to_cqlObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/datastax_rails/cql/delete.rb', line 23

def to_cql
  @values = []
  stmt = "DELETE #{@columns.join(',')} FROM #{@klass.column_family} "
  stmt << "AND TIMESTAMP #{@timestamp} " if @timestamp
  conditions = []

  @key.each do |col, val|
    conditions << "\"#{col}\" = ?"
    @values << val
  end

  stmt << "WHERE #{conditions.join(' AND ')}"

  stmt
end