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.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 50 def initialize(cluster, keyspace = nil) @cluster = cluster @sessions = {} if keyspace @session = cluster.connect(keyspace) @sessions[keyspace] = @session else @session = @cluster.connect() @sessions[:default] = @session end end |
Class Method Details
.connect(options) ⇒ Object
36 37 38 39 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 36 def self.connect() @cluster = Cassandra.cluster() self.new(@cluster) end |
Instance Method Details
#batch(type = :logged, options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 71 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
81 82 83 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 81 def close @session.close end |
#connected? ⇒ Boolean
89 90 91 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 89 def connected? @session.instance_variable_get('@state') == :connected end |
#execute(*args) ⇒ Object
62 63 64 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 62 def execute(*args) @session.execute(*args) end |
#keyspace ⇒ Object
85 86 87 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 85 def keyspace @session.keyspace end |
#prepare(statement, options = {}) ⇒ Object
66 67 68 69 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 66 def prepare(statement, = {}) s = @session.prepare(statement, ) PreparedStatement.new(self, s) end |
#use(keyspace) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/cassandra_migrations/cql-rb-wrapper.rb', line 41 def use(keyspace) if @sessions[keyspace] @session = @sessions[keyspace] else @session = @cluster.connect(keyspace) @sessions[keyspace] = @session end end |