Class: Cequel::Metal::Row

Inherits:
ActiveSupport::HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/cequel/metal/row.rb

Overview

A result row from a CQL query. Acts as a hash of column names to values, but also exposes TTLs and writetimes

Since:

  • 1.0.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRow

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 a new instance of Row.

Since:

  • 1.0.0



37
38
39
40
41
# File 'lib/cequel/metal/row.rb', line 37

def initialize
  super(ActiveSupport::HashWithIndifferentAccess.new)
  @ttls = ActiveSupport::HashWithIndifferentAccess.new
  @writetimes = ActiveSupport::HashWithIndifferentAccess.new
end

Class Method Details

.from_result_row(result_row) ⇒ Row

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.

Encapsulate a result row from the driver

Parameters:

  • result_row (Hash)

    row from underlying driver

Returns:

  • (Row)

    encapsulated row

Since:

  • 1.0.0



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cequel/metal/row.rb', line 19

def self.from_result_row(result_row)
  if result_row
    new.tap do |row|
      result_row.each_pair do |name, value|
        if name =~ /^(ttl|writetime)\((.+)\)$/
          if $1 == 'ttl' then row.set_ttl($2, value)
          else row.set_writetime($2, value)
          end
        else row[name] = value
        end
      end
    end
  end
end

Instance Method Details

#set_ttl(column, value) ⇒ Object

Since:

  • 1.0.0



65
66
67
# File 'lib/cequel/metal/row.rb', line 65

def set_ttl(column, value)
  @ttls[column] = value
end

#set_writetime(column, value) ⇒ Object

Since:

  • 1.0.0



70
71
72
# File 'lib/cequel/metal/row.rb', line 70

def set_writetime(column, value)
  @writetimes[column] = value
end

#ttl(column) ⇒ Integer

Get the TTL (time-to-live) of a column

Parameters:

  • column (Symbol)

    column name

Returns:

  • (Integer)

    TTL of column in seconds

Since:

  • 1.0.0



49
50
51
# File 'lib/cequel/metal/row.rb', line 49

def ttl(column)
  @ttls[column]
end

#writetime(column) ⇒ Integer Also known as: timestamp

Get the writetime of a column

Parameters:

  • column (Symbol)

    column name

Returns:

  • (Integer)

    writetime of column in nanoseconds since epoch

Since:

  • 1.0.0



59
60
61
# File 'lib/cequel/metal/row.rb', line 59

def writetime(column)
  @writetimes[column]
end