Class: Cql::Client::KeyspaceChanger

Inherits:
Object
  • Object
show all
Defined in:
lib/cql/client/keyspace_changer.rb

Constant Summary collapse

KEYSPACE_NAME_PATTERN =
/^\w[\w\d_]*$|^"\w[\w\d_]*"$/

Instance Method Summary collapse

Constructor Details

#initializeKeyspaceChanger

Returns a new instance of KeyspaceChanger.



9
10
11
# File 'lib/cql/client/keyspace_changer.rb', line 9

def initialize
  @request_runner = RequestRunner.new
end

Instance Method Details

#use_keyspace(keyspace, connection) ⇒ Object



13
14
15
16
17
18
# File 'lib/cql/client/keyspace_changer.rb', line 13

def use_keyspace(keyspace, connection)
  return Future.resolved(connection) unless keyspace
  return Future.failed(InvalidKeyspaceNameError.new(%("#{keyspace}" is not a valid keyspace name))) unless valid_keyspace_name?(keyspace)
  request = Protocol::QueryRequest.new("USE #{keyspace}", :one)
  @request_runner.execute(connection, request).map { connection }
end