Class: DatastaxRails::Cql::Update
- Defined in:
- lib/datastax_rails/cql/update.rb
Instance Method Summary collapse
- #columns(columns) ⇒ Object
-
#initialize(klass, key) ⇒ Update
constructor
A new instance of Update.
- #limit(limit) ⇒ Object
- #timestamp(timestamp) ⇒ Object
- #to_cql ⇒ Object
- #ttl(ttl) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(klass, key) ⇒ Update
Returns a new instance of Update.
4 5 6 7 8 9 |
# File 'lib/datastax_rails/cql/update.rb', line 4 def initialize(klass, key) @klass = klass @key = key @columns = {} super end |
Instance Method Details
#columns(columns) ⇒ Object
11 12 13 14 |
# File 'lib/datastax_rails/cql/update.rb', line 11 def columns(columns) @columns.merge!(columns) self end |
#limit(limit) ⇒ Object
16 17 18 19 |
# File 'lib/datastax_rails/cql/update.rb', line 16 def limit(limit) @limit = limit self end |
#timestamp(timestamp) ⇒ Object
26 27 28 29 |
# File 'lib/datastax_rails/cql/update.rb', line 26 def () @timestamp = self end |
#to_cql ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/datastax_rails/cql/update.rb', line 31 def to_cql stmt = "update #{@klass.column_family} " stmt << "AND TTL #{@ttl} " if @ttl stmt << "AND TIMESTAMP #{@timestamp}" if @timestamp 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 ')}" stmt.force_encoding('UTF-8') end |
#ttl(ttl) ⇒ Object
21 22 23 24 |
# File 'lib/datastax_rails/cql/update.rb', line 21 def ttl(ttl) @ttl = ttl self end |