Class: DatastaxRails::Cql::CreateKeyspace

Inherits:
Base show all
Defined in:
lib/datastax_rails/cql/create_keyspace.rb

Overview

CQL Generation for CREATE KEYSPACE

Instance Method Summary collapse

Methods inherited from Base

#execute, #using

Constructor Details

#initialize(ks_name) ⇒ CreateKeyspace

Returns a new instance of CreateKeyspace.



5
6
7
8
# File 'lib/datastax_rails/cql/create_keyspace.rb', line 5

def initialize(ks_name)
  @ks_name = ks_name
  @strategy_options = {}
end

Instance Method Details

#strategy_class(sc) ⇒ Object



10
11
12
13
# File 'lib/datastax_rails/cql/create_keyspace.rb', line 10

def strategy_class(sc)
  @strategy_class = sc
  self
end

#strategy_options(so) ⇒ Object



15
16
17
18
# File 'lib/datastax_rails/cql/create_keyspace.rb', line 15

def strategy_options(so)
  @strategy_options.merge!(so)
  self
end

#to_cqlObject



20
21
22
23
24
25
26
27
28
# File 'lib/datastax_rails/cql/create_keyspace.rb', line 20

def to_cql
  stmt = "CREATE KEYSPACE #{@ks_name} WITH REPLICATION = {'class' : '#{@strategy_class}'"

  @strategy_options.each do |key, value|
    stmt << ", '#{key}' : '#{value}'"
  end
  stmt << '}'
  stmt
end