Class: Cequel::Keyspace
- Inherits:
-
Object
- Object
- Cequel::Keyspace
- Defined in:
- lib/cequel/keyspace.rb
Overview
Handle to a Cassandra keyspace.
Instance Attribute Summary collapse
- #connection ⇒ Object
-
#logger ⇒ Object
writeonly
Set a logger for logging queries.
-
#slowlog ⇒ Object
writeonly
Set a logger for logging queries.
-
#slowlog_threshold ⇒ Object
writeonly
Set a logger for logging queries.
Instance Method Summary collapse
-
#[](column_family_name) ⇒ DataSet
Get DataSet encapsulating a column family in this keyspace.
-
#batch(options = {}) ⇒ Object
Execute write operations in a batch.
-
#execute(statement, *bind_vars) ⇒ Object
Execute a CQL query in this keyspace.
-
#initialize(configuration = {}) ⇒ Keyspace
constructor
private
A new instance of Keyspace.
-
#write(statement, *bind_vars) ⇒ Object
Write data to this keyspace using a CQL query.
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.
17 18 19 20 21 |
# File 'lib/cequel/keyspace.rb', line 17 def initialize(configuration = {}) @name = configuration[:keyspace] @hosts = configuration[:host] || configuration[:hosts] @thrift_options = configuration[:thrift].try(:symbolize_keys) end |
Instance Attribute Details
#connection ⇒ Object
23 24 25 26 27 |
# File 'lib/cequel/keyspace.rb', line 23 def connection @connection ||= CassandraCQL::Database.new( @hosts, {:keyspace => @name}, @thrift_options ) end |
#logger=(value) ⇒ Object (writeonly)
Set a logger for logging queries. Queries logged at INFO level
11 12 13 |
# File 'lib/cequel/keyspace.rb', line 11 def logger=(value) @logger = value end |
#slowlog=(value) ⇒ Object (writeonly)
Set a logger for logging queries. Queries logged at INFO level
11 12 13 |
# File 'lib/cequel/keyspace.rb', line 11 def slowlog=(value) @slowlog = value end |
#slowlog_threshold=(value) ⇒ Object (writeonly)
Set a logger for logging queries. Queries logged at INFO level
11 12 13 |
# File 'lib/cequel/keyspace.rb', line 11 def slowlog_threshold=(value) @slowlog_threshold = value end |
Instance Method Details
#[](column_family_name) ⇒ DataSet
Get DataSet encapsulating a column family in this keyspace
35 36 37 |
# File 'lib/cequel/keyspace.rb', line 35 def [](column_family_name) DataSet.new(column_family_name.to_sym, self) end |
#batch(options = {}) ⇒ Object
Execute write operations in a batch. Any inserts, updates, and deletes inside this method’s block will be executed inside a CQL BATCH operation.
78 79 80 81 82 83 84 |
# File 'lib/cequel/keyspace.rb', line 78 def batch( = {}) old_batch, @batch = @batch, Batch.new(self, ) yield @batch.apply ensure @batch = old_batch end |
#execute(statement, *bind_vars) ⇒ Object
Execute a CQL query in this keyspace.
45 46 47 48 49 |
# File 'lib/cequel/keyspace.rb', line 45 def execute(statement, *bind_vars) log('CQL', statement, *bind_vars) do connection.execute(statement, *bind_vars) end end |
#write(statement, *bind_vars) ⇒ Object
Write data to this keyspace using a CQL query. Will be included the current batch operation if one is present.
57 58 59 60 61 62 63 |
# File 'lib/cequel/keyspace.rb', line 57 def write(statement, *bind_vars) if @batch @batch.execute(statement, *bind_vars) else execute(statement, *bind_vars) end end |