class ROM::Cassandra::Dataset

The dataset describes a table of the Cassandra cluster

@api private

Attributes

keyspace[R]

@!attribute [r] keyspace

@return [Symbol] The name of the current keyspace

query[R]

@!attribute [r] query

@return [QueryBuilder::Statement] The lazy query to the current table

session[R]

@!attribute [r] session

@return [ROM::Cassandra::Session] The open session to a Cassandra cluster

table[R]

@!attribute [r] table

@return [Symbol] The name of the current table

Public Class Methods

new(session, keyspace, table, query = nil) click to toggle source

Initializes the dataset for given column family and command options

@param [ROM::Cassandra::Session] session @param [#to_sym] keyspace @param [#to_sym] table @param [ROM::Cassandra::Query] query

@api private

# File lib/rom/cassandra/dataset.rb, line 47
def initialize(session, keyspace, table, query = nil)
  @session  = session
  @keyspace = keyspace.to_sym if keyspace
  @table    = table.to_sym if table
  @query    = query || Query.new.keyspace(keyspace).table(table)
end

Public Instance Methods

batch() click to toggle source

Returns the new dataset carriyng the batch query

The batch query doesn’t restricted by any table or keyspace

@return [ROM::Relation::Dataset]

# File lib/rom/cassandra/dataset.rb, line 60
def batch
  reload nil, nil, Query.new.batch
end
each() { |item| ... } click to toggle source

Sends the [#query] to Cassandra and iterates through results

@return [Enumerator]

@yieldparam [Hash] tuples from the dataset @yieldreturn [self] itself

# File lib/rom/cassandra/dataset.rb, line 81
def each
  return to_enum unless block_given?
  session.call(query).each { |item| yield(item) }
end
get(*args) click to toggle source

Returns new dataset with ‘select` method applied to the [#query]

@param [Array, Hash, nil] args

@return [ROM::Relation::Dataset]

# File lib/rom/cassandra/dataset.rb, line 70
def get(*args)
  reload keyspace, table, query.select(*args)
end

Private Instance Methods

method_missing(name, *args) click to toggle source
# File lib/rom/cassandra/dataset.rb, line 92
def method_missing(name, *args)
  reload keyspace, table, query.public_send(name, *args)
end
reload(*args) click to toggle source
# File lib/rom/cassandra/dataset.rb, line 88
def reload(*args)
  self.class.new(session, *args)
end
respond_to_missing?(name, *) click to toggle source
# File lib/rom/cassandra/dataset.rb, line 96
def respond_to_missing?(name, *)
  query.respond_to?(name)
end