Class: Cassava::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cassava/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, opts = {}) ⇒ Client

Returns a new instance of Client.

Parameters:

  • session (Cassandra::Session)

    The session object

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :logger (Object)

    responding to :debug, :info, :warn, :error, :fatal



7
8
9
10
11
# File 'lib/cassava/client.rb', line 7

def initialize(session, opts = {})
  @session = session
  logger = opts[:logger] || NullLogger.new
  @executor = Executor.new(session, logger)
end

Instance Attribute Details

#executorObject (readonly)

Returns the value of attribute executor.



3
4
5
# File 'lib/cassava/client.rb', line 3

def executor
  @executor
end

#sessionObject (readonly)

Returns the value of attribute session.



3
4
5
# File 'lib/cassava/client.rb', line 3

def session
  @session
end

Instance Method Details

#delete(table, columns = nil) ⇒ StatementBuilder

Returns A statement builder representing the partially completed statement.

Parameters:

  • table (Symbol)

    the table name

  • columns (Array<String] A list of columns that will be deleted. If nil, all columns will be deleted.) (defaults to: nil)

    olumns [Array<String] A list of columns that will be deleted. If nil, all columns will be deleted.

Returns:

  • (StatementBuilder)

    A statement builder representing the partially completed statement.



35
36
37
# File 'lib/cassava/client.rb', line 35

def delete(table, columns = nil)
  StatementBuilder.new(executor).delete(table, columns)
end

#execute(statement, opts = {}) ⇒ Object

Pass a raw query to execute asynchronously to the underlying session object.

Parameters:

  • statement (String)

    The statment to execute

  • opts (Hash) (defaults to: {})

    options accepted by Cassandra::Session



49
50
51
# File 'lib/cassava/client.rb', line 49

def execute(statement, opts = {})
  executor.execute(statement, opts)
end

#execute_async(statement, opts = {}) ⇒ Object

Pass a raw query to execute synchronously to the underlying session object.

Parameters:

  • statement (String)

    The statment to execute

  • opts (Hash) (defaults to: {})

    options accepted by Cassandra::Session



42
43
44
# File 'lib/cassava/client.rb', line 42

def execute_async(statement, opts = {})
  executor.execute_async(statement, opts)
end

#insert(table, data) ⇒ Object

Parameters:

  • table (Symbol)

    the table name

  • data (Hash)

    A hash of column names to data, which will be inserted into the table



20
21
22
23
# 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) ⇒ Object

See Also:



14
15
16
# 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) ⇒ StatementBuilder

Returns A statement builder representing the partially completed statement.

Parameters:

  • table (Symbol)

    the table name

  • columns (Array<Symbol>) (defaults to: nil)

    An optional list of column names (as symbols), to only select those columns

Returns:

  • (StatementBuilder)

    A statement builder representing the partially completed statement.



28
29
30
# File 'lib/cassava/client.rb', line 28

def select(table, columns = nil)
  StatementBuilder.new(executor).select(table, columns)
end