Class: CassandraObject::Schema
- Inherits:
-
Object
- Object
- CassandraObject::Schema
- Defined in:
- lib/cassandra_object/schema.rb
Constant Summary collapse
- DEFAULT_CREATE_KEYSPACE =
{ 'strategy_class' => 'SimpleStrategy', 'strategy_options' => 'replication_factor:1' }
Class 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
- .create_table(table_name, options = {}) ⇒ 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, confirm = false) ⇒ Object
- .drop_table(table_name, confirm = false) ⇒ Object
Class Method Details
.add_index(column_family, column, index_name = nil) ⇒ Object
54 55 56 57 |
# File 'lib/cassandra_object/schema.rb', line 54 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
41 42 43 44 |
# File 'lib/cassandra_object/schema.rb', line 41 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
33 34 35 |
# File 'lib/cassandra_object/schema.rb', line 33 def create_column_family(column_family, = {}) create_table column_family, end |
.create_keyspace(keyspace, options = nil) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/cassandra_object/schema.rb', line 12 def create_keyspace(keyspace, = nil) stmt = "CREATE KEYSPACE #{keyspace} WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };" ||= {} #DEFAULT_CREATE_KEYSPACE system_execute stmt #adapter.statement_with_options(stmt, options) end |
.create_table(table_name, options = {}) ⇒ Object
37 38 39 |
# File 'lib/cassandra_object/schema.rb', line 37 def create_table(table_name, = {}) adapter.create_table table_name, end |
.drop_column_family(column_family) ⇒ Object
46 47 48 |
# File 'lib/cassandra_object/schema.rb', line 46 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.
60 61 62 |
# File 'lib/cassandra_object/schema.rb', line 60 def drop_index(index_name) keyspace_execute "DROP INDEX #{index_name}" end |
.drop_keyspace(keyspace, confirm = false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cassandra_object/schema.rb', line 20 def drop_keyspace(keyspace, confirm = false) if adapter.cassandra_version < 3 count = (system_execute "SELECT count(*) FROM schema_columnfamilies where keyspace_name = '#{keyspace}' ALLOW FILTERING;").rows.first['count'] else count = (system_schema_execute "SELECT count(*) FROM tables where keyspace_name = '#{keyspace}';").rows.first['count'] end if confirm || count == 0 system_execute "DROP KEYSPACE #{keyspace}" else raise "Cannot drop keyspace #{keyspace}. You must delete all tables before" end end |
.drop_table(table_name, confirm = false) ⇒ Object
50 51 52 |
# File 'lib/cassandra_object/schema.rb', line 50 def drop_table(table_name, confirm = false) adapter.drop_table table_name, confirm end |