Class: DatastaxRails::Cql::Update
Overview
CQL generation for UPDATE
Instance Method Summary
collapse
#if_exists, #if_not_exists, #iff, #to_cql_with_transactions
Methods inherited from Base
#execute, #using
Constructor Details
#initialize(klass, key) ⇒ Update
Returns a new instance of Update.
5
6
7
8
9
10
|
# File 'lib/datastax_rails/cql/update.rb', line 5
def initialize(klass, key)
@klass = klass
@key = key
@columns = {}
super
end
|
Instance Method Details
#columns(columns) ⇒ Object
12
13
14
15
|
# File 'lib/datastax_rails/cql/update.rb', line 12
def columns(columns)
@columns.merge!(columns)
self
end
|
#limit(limit) ⇒ Object
17
18
19
20
|
# File 'lib/datastax_rails/cql/update.rb', line 17
def limit(limit)
@limit = limit
self
end
|
#timestamp(timestamp) ⇒ Object
27
28
29
30
|
# File 'lib/datastax_rails/cql/update.rb', line 27
def timestamp(timestamp)
@timestamp = timestamp
self
end
|
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/datastax_rails/cql/update.rb', line 32
def to_cql
stmt = "update #{@klass.column_family} "
if @ttl || @timestamp
stmt << 'USING '
stmt << "TTL #{@ttl} " if @ttl
stmt << 'AND ' if @ttl && @timestamp
stmt << "TIMESTAMP #{@timestamp} " if @timestamp
end
unless @columns.empty?
stmt << 'SET '
updates = []
@columns.each do |k, v|
@values << v
updates << "\"#{k}\" = ?"
end
stmt << updates.join(', ')
end
conditions = []
@key.each do |k, v|
conditions << "\"#{k}\" = ?"
@values << v
end
stmt << " WHERE #{conditions.join(' AND ')}"
end
|
22
23
24
25
|
# File 'lib/datastax_rails/cql/update.rb', line 22
def ttl(ttl)
@ttl = ttl
self
end
|