Class: Believer::KeySpace

Inherits:
Object
  • Object
show all
Includes:
CqlHelper
Defined in:
lib/believer/key_space.rb

Constant Summary collapse

DEFAULT_PROPERTIES =
{:replication => {:class => 'SimpleStrategy', :replication_factor => 1}}

Constants included from CqlHelper

CqlHelper::CQL_TIMESTAMP_FORMAT

Instance Method Summary collapse

Methods included from CqlHelper

#escape_special_chars, #to_cql_literal, #to_cql_properties, #to_hex_literal

Constructor Details

#initialize(environment) ⇒ KeySpace

Returns a new instance of KeySpace.



7
8
9
# File 'lib/believer/key_space.rb', line 7

def initialize(environment)
  @environment = environment
end

Instance Method Details

#create(properties = {}) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/believer/key_space.rb', line 21

def create(properties = {})
  conn = @environment.create_connection(:connect_to_keyspace => false)
  ks_props = DEFAULT_PROPERTIES.merge(properties)
  ks_props_s = to_cql_properties(ks_props)
  ks_def = "CREATE KEYSPACE #{name} WITH #{ks_props_s}"
  conn.execute(ks_def)
end

#dropObject



15
16
17
18
19
# File 'lib/believer/key_space.rb', line 15

def drop
  connection = @environment.create_connection(:connect_to_keyspace => false)
  connection.execute("DROP KEYSPACE #{name}")
  connection.close
end

#nameObject



11
12
13
# File 'lib/believer/key_space.rb', line 11

def name
  @environment.connection_configuration[:keyspace]
end