Class: Cequel::Metal::Keyspace
- Inherits:
-
Object
- Object
- Cequel::Metal::Keyspace
- Extended by:
- Forwardable
- Includes:
- Logging
- Defined in:
- lib/cequel/metal/keyspace.rb
Overview
Handle to a Cassandra keyspace (database). Keyspace objects are factories for DataSet instances and provide a handle to a Schema::Keyspace instance.
Instance Attribute Summary collapse
-
#configuration ⇒ Hash
readonly
Configuration options for this keyspace.
-
#name ⇒ String
readonly
Name of the keyspace.
Instance Method Summary collapse
-
#[](table_name) ⇒ DataSet
Data set encapsulating table.
-
#batch { ... } ⇒ Object
Execute write operations in a batch.
-
#clear_active_connections! ⇒ void
Clears all active connections.
-
#configure(configuration = {}) ⇒ void
Configure this keyspace from a hash of options.
-
#execute(statement, *bind_vars) ⇒ void
Execute a CQL query in this keyspace.
-
#initialize(configuration = {}) ⇒ Keyspace
constructor
private
A new instance of Keyspace.
-
#schema ⇒ Schema::Keyspace
Schema object providing full read/write access to database schema.
-
#write(statement, *bind_vars) ⇒ void
Write data to this keyspace using a CQL query.
Methods included from Logging
#logger=, #slowlog=, #slowlog_threshold=
Constructor Details
#initialize(configuration = {}) ⇒ Keyspace
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 Keyspace.
40 41 42 |
# File 'lib/cequel/metal/keyspace.rb', line 40 def initialize(configuration={}) configure(configuration) end |
Instance Attribute Details
#configuration ⇒ Hash (readonly)
Returns configuration options for this keyspace.
13 14 15 |
# File 'lib/cequel/metal/keyspace.rb', line 13 def configuration @configuration end |
#name ⇒ String (readonly)
Returns name of the keyspace.
15 16 17 |
# File 'lib/cequel/metal/keyspace.rb', line 15 def name @name end |
Instance Method Details
#[](table_name) ⇒ DataSet
Returns data set encapsulating table.
81 82 83 |
# File 'lib/cequel/metal/keyspace.rb', line 81 def [](table_name) DataSet.new(table_name.to_sym, self) end |
#batch { ... } ⇒ Object
If this method is created while already in a batch of the same type (logged or unlogged), this method is a no-op.
Execute write operations in a batch. Any inserts, updates, and deletes inside this method’s block will be executed inside a CQL BATCH operation.
32 |
# File 'lib/cequel/metal/keyspace.rb', line 32 def_delegator :batch_manager, :batch |
#clear_active_connections! ⇒ void
This method returns an undefined value.
Clears all active connections
105 106 107 108 109 |
# File 'lib/cequel/metal/keyspace.rb', line 105 def clear_active_connections! if defined? @connection_pool remove_instance_variable(:@connection_pool) end end |
#configure(configuration = {}) ⇒ void
This method returns an undefined value.
Configure this keyspace from a hash of options
60 61 62 63 64 65 66 67 68 |
# File 'lib/cequel/metal/keyspace.rb', line 60 def configure(configuration = {}) @configuration = configuration @hosts = configuration.fetch( :host, configuration.fetch(:hosts, '127.0.0.1:9160')) @thrift_options = configuration[:thrift].try(:symbolize_keys) || {} @name = configuration[:keyspace] # reset the connections clear_active_connections! end |
#execute(statement, *bind_vars) ⇒ void
This method returns an undefined value.
Execute a CQL query in this keyspace
92 93 94 95 96 97 98 |
# File 'lib/cequel/metal/keyspace.rb', line 92 def execute(statement, *bind_vars) log('CQL', statement, *bind_vars) do with_connection do |conn| conn.execute(statement, *bind_vars) end end end |
#schema ⇒ Schema::Keyspace
Returns schema object providing full read/write access to database schema.
73 74 75 |
# File 'lib/cequel/metal/keyspace.rb', line 73 def schema Schema::Keyspace.new(self) end |
#write(statement, *bind_vars) ⇒ void
This method returns an undefined value.
Write data to this keyspace using a CQL query. Will be included the current batch operation if one is present.
26 |
# File 'lib/cequel/metal/keyspace.rb', line 26 def_delegator :write_target, :execute, :write |