Class: Client
- Inherits:
-
Object
- Object
- Client
- Defined in:
- lib/cassandra_migrations/cql-rb-wrapper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #batch(type = :logged, options = {}) ⇒ Object
- #close ⇒ Object
- #connected? ⇒ Boolean
- #execute(*args) ⇒ Object
-
#initialize(cluster, keyspace = nil) ⇒ Client
constructor
A new instance of Client.
- #keyspace ⇒ Object
- #prepare(statement, options = {}) ⇒ Object
- #use(keyspace) ⇒ Object
Constructor Details
#initialize(cluster, keyspace = nil) ⇒ Client
Returns a new instance of Client.
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 56 def initialize(cluster, keyspace = nil) @cluster = cluster @sessions = {} if keyspace Rails.logger.try(:info, "Creating Cassandra session: #{keyspace.inspect}") @session = cluster.connect(keyspace) @sessions[keyspace] = @session else Rails.logger.try(:info, "Creating Cassandra session: [no keyspace]") @session = @cluster.connect() @sessions[:default] = @session end end |
Class Method Details
.connect(options) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 36 def self.connect() Rails.logger.try(:info, "Connecting to Cassandra cluster: #{}") unless @cluster = Cassandra.cluster() raise CassandraMigrations::Errors::ClusterError.new() end self.new(@cluster) end |
Instance Method Details
#batch(type = :logged, options = {}) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 79 def batch(type = :logged, = {}) batch = BatchStatement.new(self, @session.send(:"#{type}_batch")) if block_given? yield(batch) batch.execute() else batch end end |
#close ⇒ Object
89 90 91 92 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 89 def close Rails.logger.try(:info, "Closing Cassandra session: #{@session.inspect}") @session.close end |
#connected? ⇒ Boolean
98 99 100 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 98 def connected? @session.instance_variable_get('@state') == :connected end |
#execute(*args) ⇒ Object
70 71 72 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 70 def execute(*args) @session.execute(*args) end |
#keyspace ⇒ Object
94 95 96 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 94 def keyspace @session.keyspace end |
#prepare(statement, options = {}) ⇒ Object
74 75 76 77 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 74 def prepare(statement, = {}) s = @session.prepare(statement, ) PreparedStatement.new(self, s) end |
#use(keyspace) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 46 def use(keyspace) if @sessions[keyspace] @session = @sessions[keyspace] else Rails.logger.try(:info, "Creating Cassandra session: #{keyspace.inspect}") @session = @cluster.connect(keyspace) @sessions[keyspace] = @session end end |