class Client

Public Class Methods

connect(options) click to toggle source
# File lib/cassandra_migrations/cql-rb-wrapper.rb, line 36
def self.connect(options)
  Rails.logger.try(:info, "Connecting to Cassandra cluster: #{options}")

  unless @cluster = Cassandra.cluster(options)
    raise CassandraMigrations::Errors::ClusterError.new(options)
  end

  self.new(@cluster)
end
new(cluster, keyspace = nil) click to toggle source
# 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

Public Instance Methods

batch(type = :logged, options = {}) { |batch| ... } click to toggle source
# File lib/cassandra_migrations/cql-rb-wrapper.rb, line 79
def batch(type = :logged, options = {})
  batch = BatchStatement.new(self, @session.send(:"#{type}_batch"))
  if block_given?
    yield(batch)
    batch.execute(options)
  else
    batch
  end
end
close() click to toggle source
# 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?() click to toggle source
# File lib/cassandra_migrations/cql-rb-wrapper.rb, line 98
def connected?
  @session.instance_variable_get('@state') == :connected
end
execute(*args) click to toggle source
# File lib/cassandra_migrations/cql-rb-wrapper.rb, line 70
def execute(*args)
  @session.execute(*args)
end
keyspace() click to toggle source
# File lib/cassandra_migrations/cql-rb-wrapper.rb, line 94
def keyspace
  @session.keyspace
end
prepare(statement, options = {}) click to toggle source
# File lib/cassandra_migrations/cql-rb-wrapper.rb, line 74
def prepare(statement, options = {})
  s = @session.prepare(statement, options)
  PreparedStatement.new(self, s)
end
use(keyspace) click to toggle source
# 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