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
- #add_index(column_family, column, index_name = nil) ⇒ Object
- #alter_column_family(column_family, instruction, options = {}) ⇒ Object
- #create_column_family(column_family, options = {}) ⇒ Object
- #create_keyspace(keyspace, options = nil) ⇒ Object
- #drop_column_family(column_family) ⇒ Object
-
#drop_index(index_name) ⇒ Object
If the index was not given a name during creation, the index name is <columnfamily_name>_<column_name>_idx.
- #drop_keyspace(keyspace) ⇒ Object
- #keyspace_execute(cql) ⇒ Object
- #system_execute(cql) ⇒ Object
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, = {}) stmt = "ALTER TABLE #{column_family} #{instruction}" keyspace_execute adapter.(stmt, ) 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, = {}) create_table column_family, 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, = nil) stmt = "CREATE KEYSPACE #{keyspace}" ||= DEFAULT_CREATE_KEYSPACE system_execute adapter.(stmt, ) 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 |