Sha256: 091d7ca36d266635423f5512d9a2167c09f15727e747d0168bdb31379f56ba12
Contents?: true
Size: 1.6 KB
Versions: 3
Compression:
Stored size: 1.6 KB
Contents
require 'cassandra_object/schema/tasks' module CassandraObject class Schema extend Tasks class << self DEFAULT_CREATE_KEYSPACE = { 'strategy_class' => 'SimpleStrategy', 'strategy_options:replication_factor' => 1 } def create_keyspace(keyspace, options = {}) stmt = "CREATE KEYSPACE #{keyspace}" if options.empty? options = DEFAULT_CREATE_KEYSPACE end system_execute statement_with_options(stmt, options) end def drop_keyspace(keyspace) system_execute "DROP KEYSPACE #{keyspace}" end def create_column_family(column_family, options = {}) stmt = "CREATE COLUMNFAMILY #{column_family} " + "(KEY varchar PRIMARY KEY)" execute statement_with_options(stmt, options) end def alter_column_family(column_family, options) stmt = "ALTER TABLE #{column_family}" execute statement_with_options(stmt, options) end def add_index() end private def statement_with_options(stmt, options) if options.any? with_stmt = options.map do |k,v| "#{k} = #{CassandraCQL::Statement.quote(v)}" end.join(' AND ') stmt << " WITH #{with_stmt}" end stmt end def execute(cql) CassandraObject::Base.execute_cql cql end def system_execute(cql) @system_cql ||= CassandraCQL::Database.new(CassandraObject::Base.config.servers, keyspace: 'system') @system_cql.execute cql end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
gotime-cassandra_object-4.7.1 | lib/cassandra_object/schema.rb |
gotime-cassandra_object-4.7.0 | lib/cassandra_object/schema.rb |
gotime-cassandra_object-4.6.0 | lib/cassandra_object/schema.rb |