Module: Superstore::Statements

Included in:
CassandraSchema
Defined in:
lib/superstore/cassandra_schema/statements.rb

Constant Summary collapse

DEFAULT_CREATE_KEYSPACE =
{
  'strategy_class' => 'SimpleStrategy',
  'strategy_options:replication_factor' => 1
}

Instance Method Summary collapse

Instance Method Details

#add_index(column_family, column, index_name = nil) ⇒ Object



33
34
35
36
# File 'lib/superstore/cassandra_schema/statements.rb', line 33

def add_index(column_family, column, index_name = nil)
  stmt = "CREATE INDEX #{index_name.nil? ? '' : index_name} ON #{column_family} (#{column})"
  keyspace_execute stmt
end

#alter_column_family(column_family, instruction, options = {}) ⇒ Object



24
25
26
27
# File 'lib/superstore/cassandra_schema/statements.rb', line 24

def alter_column_family(column_family, instruction, options = {})
  stmt = "ALTER TABLE #{column_family} #{instruction}"
  keyspace_execute adapter.statement_with_options(stmt, options)
end

#create_column_family(column_family, options = {}) ⇒ Object



20
21
22
# File 'lib/superstore/cassandra_schema/statements.rb', line 20

def create_column_family(column_family, options = {})
  create_table column_family, options
end

#create_keyspace(keyspace, options = nil) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/superstore/cassandra_schema/statements.rb', line 8

def create_keyspace(keyspace, options = nil)
  stmt = "CREATE KEYSPACE #{keyspace}"

  options ||= DEFAULT_CREATE_KEYSPACE

  system_execute adapter.statement_with_options(stmt, options)
end

#drop_column_family(column_family) ⇒ Object



29
30
31
# File 'lib/superstore/cassandra_schema/statements.rb', line 29

def drop_column_family(column_family)
  drop_table column_family
end

#drop_index(index_name) ⇒ Object

If the index was not given a name during creation, the index name is <columnfamily_name>_<column_name>_idx.



39
40
41
# File 'lib/superstore/cassandra_schema/statements.rb', line 39

def drop_index(index_name)
  keyspace_execute "DROP INDEX #{index_name}"
end

#drop_keyspace(keyspace) ⇒ Object



16
17
18
# File 'lib/superstore/cassandra_schema/statements.rb', line 16

def drop_keyspace(keyspace)
  system_execute "DROP KEYSPACE #{keyspace}"
end

#keyspace_execute(cql) ⇒ Object



44
45
46
# File 'lib/superstore/cassandra_schema/statements.rb', line 44

def keyspace_execute(cql)
  adapter.schema_execute cql, Superstore::Base.config[:keyspace]
end

#system_execute(cql) ⇒ Object



48
49
50
# File 'lib/superstore/cassandra_schema/statements.rb', line 48

def system_execute(cql)
  adapter.schema_execute cql, 'system'
end