Sha256: a2c8fd3603c345935cb56fbbad2952f68f40be52e716c265f290ecd608896182

Contents?: true

Size: 1.43 KB

Versions: 18

Compression:

Stored size: 1.43 KB

Contents

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

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

      options ||= DEFAULT_CREATE_KEYSPACE

      system_execute adapter.statement_with_options(stmt, options)
    end

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

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

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

    def drop_column_family(column_family)
      drop_table column_family
    end

    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

    # If the index was not given a name during creation, the index name is <columnfamily_name>_<column_name>_idx.
    def drop_index(index_name)
      keyspace_execute "DROP INDEX #{index_name}"
    end


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

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
superstore-1.2.0 lib/superstore/cassandra_schema/statements.rb
superstore-1.1.4 lib/superstore/cassandra_schema/statements.rb
superstore-1.1.3 lib/superstore/cassandra_schema/statements.rb
superstore-1.1.2 lib/superstore/cassandra_schema/statements.rb
superstore-1.1.1 lib/superstore/cassandra_schema/statements.rb
superstore-1.1.0 lib/superstore/cassandra_schema/statements.rb
superstore-1.0.12 lib/superstore/cassandra_schema/statements.rb
superstore-1.0.11 lib/superstore/cassandra_schema/statements.rb
superstore-1.0.10 lib/superstore/cassandra_schema/statements.rb
superstore-1.0.9 lib/superstore/cassandra_schema/statements.rb
superstore-1.0.8 lib/superstore/cassandra_schema/statements.rb
superstore-1.0.7 lib/superstore/cassandra_schema/statements.rb
superstore-1.0.6 lib/superstore/cassandra_schema/statements.rb
superstore-1.0.5 lib/superstore/cassandra_schema/statements.rb
superstore-1.0.4 lib/superstore/cassandra_schema/statements.rb
superstore-1.0.3 lib/superstore/cassandra_schema/statements.rb
superstore-1.0.2 lib/superstore/cassandra_schema/statements.rb
superstore-1.0.0 lib/superstore/cassandra_schema/statements.rb