class Cassava::Client

Attributes

executor[R]
session[R]

Public Class Methods

new(session, opts = {}) click to toggle source

@param session [Cassandra::Session] The session object @option opts [Object] :logger responding to :debug, :info, :warn, :error, :fatal

# File lib/cassava/client.rb, line 7
def initialize(session, opts = {})
  @session = session
  logger = opts[:logger] || NullLogger.new
  @executor = Executor.new(session, logger)
end

Public Instance Methods

delete(table, columns = nil) click to toggle source

@param table [Symbol] the table name @param columns [Array<String] A list of columns that will be deleted. If nil, all columns will be deleted. @return [StatementBuilder] A statement builder representing the partially completed statement.

# File lib/cassava/client.rb, line 35
def delete(table, columns = nil)
  StatementBuilder.new(executor).delete(table, columns)
end
execute(statement, opts = {}) click to toggle source

Pass a raw query to execute asynchronously to the underlying session object. @param statement [String] The statment to execute @param opts [Hash] options accepted by Cassandra::Session

# File lib/cassava/client.rb, line 49
def execute(statement, opts = {})
  executor.execute(statement, opts)
end
execute_async(statement, opts = {}) click to toggle source

Pass a raw query to execute synchronously to the underlying session object. @param statement The statment to execute @param opts [Hash] options accepted by Cassandra::Session

# File lib/cassava/client.rb, line 42
def execute_async(statement, opts = {})
  executor.execute_async(statement, opts)
end
insert(table, data) click to toggle source

@param table [Symbol] the table name @param data [Hash] A hash of column names to data, which will be inserted into the table

# File lib/cassava/client.rb, line 20
def insert(table, data)
  statement = insert_statement(table, data)
  executor.execute(statement, :arguments => data.values)
end
insert_async(table, data) click to toggle source

@see insert

# File lib/cassava/client.rb, line 14
def insert_async(table, data)
  executor.execute_async(insert_statement(table, data), :arguments => data.values)
end
select(table, columns = nil) click to toggle source

@param table [Symbol] the table name @param columns [Array<Symbol>] An optional list of column names (as symbols), to only select those columns @return [StatementBuilder] A statement builder representing the partially completed statement.

# File lib/cassava/client.rb, line 28
def select(table, columns = nil)
  StatementBuilder.new(executor).select(table, columns)
end

Private Instance Methods

insert_statement(table, data) click to toggle source
# File lib/cassava/client.rb, line 55
def insert_statement(table, data)
  column_names = data.keys
  statement_cql = "INSERT INTO #{table} (#{column_names.join(', ')}) VALUES (#{column_names.map { |x| '?' }.join(',')})"
  executor.prepare(statement_cql)
end