Module: CassandraMigrations::Cassandra

Extended by:
KeyspaceOperations, Queries
Defined in:
lib/cassandra_migrations/cassandra.rb,
lib/cassandra_migrations/cassandra/queries.rb,
lib/cassandra_migrations/cassandra/query_result.rb,
lib/cassandra_migrations/cassandra/keyspace_operations.rb

Defined Under Namespace

Modules: KeyspaceOperations, Queries Classes: QueryResult

Class Method Summary collapse

Methods included from Queries

delete!, select, truncate!, update!, write!

Methods included from KeyspaceOperations

create_keyspace!, drop_keyspace!

Class Method Details

.execute(cql) ⇒ Object



60
61
62
63
64
65
# File 'lib/cassandra_migrations/cassandra.rb', line 60

def self.execute(cql)
  connect_to_server unless client
  Rails.logger.try(:info, "\e[1;35m [Cassandra Migrations] \e[0m #{cql.to_s}")
  result = client.execute(cql)
  QueryResult.new(result) if result
end

.restart!Object



28
29
30
31
32
33
34
# File 'lib/cassandra_migrations/cassandra.rb', line 28

def self.restart!
  raise Errors::ClientNotStartedError unless client

  client.close if client && client.connected?
  self.client = nil
  start!
end

.shutdown!Object



36
37
38
39
40
41
# File 'lib/cassandra_migrations/cassandra.rb', line 36

def self.shutdown!
  raise Errors::ClientNotStartedError unless client

  client.close if client.connected?
  self.client = nil
end

.start!Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/cassandra_migrations/cassandra.rb', line 17

def self.start!
  begin
    # setup keyspace use
    use(Config.keyspace)
  rescue Errors::MissingConfigurationError
    # It's acceptable to not have a configuration file, that's why we rescue this exception.
    # On the other hand, if the user try to execute a query this same exception won't be rescued
    Rails.logger.try(:warn, "There is no config/cassandra.yml. Skipping connection to Cassandra...")
  end
end

.use(keyspace) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/cassandra_migrations/cassandra.rb', line 49

def self.use(keyspace)
  connect_to_server unless client

  begin
    client.use(keyspace)
  rescue Exception => e # keyspace does not exist
    puts "#{e} : #{e.message}"
    raise Errors::UnexistingKeyspaceError, keyspace
  end
end

.using_keyspace(keyspace, &block) ⇒ Object



43
44
45
46
47
# File 'lib/cassandra_migrations/cassandra.rb', line 43

def self.using_keyspace(keyspace, &block)
  use(keyspace)
  block.call
  use(Config.keyspace)
end