Class: Cassandra::Index
- Inherits:
-
Object
- Object
- Cassandra::Index
- Defined in:
- lib/cassandra/index.rb
Overview
Represents an index on a cassandra table
Instance Attribute Summary collapse
-
#kind ⇒ Symbol
readonly
Kind of index:
:keys
,:composites
, or:custom
. -
#name ⇒ String
readonly
Name of the index.
-
#options ⇒ Hash
readonly
Options of the index.
-
#table ⇒ Cassandra::Table
readonly
Table that the index applies to.
-
#target ⇒ String
readonly
Name of column that the index applies to.
Instance Method Summary collapse
-
#custom_class_name ⇒ String
Name of the index class if this is a custom index; nil otherwise.
-
#custom_index? ⇒ Boolean
Whether or not this index uses a custom class.
-
#to_cql ⇒ String
A cql representation of this index.
Instance Attribute Details
#kind ⇒ Symbol (readonly)
27 28 29 |
# File 'lib/cassandra/index.rb', line 27 def kind @kind end |
#name ⇒ String (readonly)
25 26 27 |
# File 'lib/cassandra/index.rb', line 25 def name @name end |
#options ⇒ Hash (readonly)
31 32 33 |
# File 'lib/cassandra/index.rb', line 31 def end |
#table ⇒ Cassandra::Table (readonly)
23 24 25 |
# File 'lib/cassandra/index.rb', line 23 def table @table end |
#target ⇒ String (readonly)
29 30 31 |
# File 'lib/cassandra/index.rb', line 29 def target @target end |
Instance Method Details
#custom_class_name ⇒ String
61 62 63 |
# File 'lib/cassandra/index.rb', line 61 def custom_class_name ['class_name'] end |
#custom_index? ⇒ Boolean
56 57 58 |
# File 'lib/cassandra/index.rb', line 56 def custom_index? !['class_name'].nil? end |
#to_cql ⇒ String
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cassandra/index.rb', line 66 def to_cql keyspace_name = Util.escape_name(@table.keyspace.name) table_name = Util.escape_name(@table.name) index_name = Util.escape_name(@name) # Target is interesting in that it's not necessarily a column name, # so we can't simply escape it. If it contains a paren, we take it as is, # otherwise assume it's a column name and escape accordingly. escaped_target = @target.include?('(') ? @target : Util.escape_name(@target) if custom_index? "CREATE CUSTOM INDEX #{index_name} ON #{keyspace_name}.#{table_name} (#{escaped_target}) " \ "USING '#{@options['class_name']}'#{options_cql};" else "CREATE INDEX #{index_name} ON #{keyspace_name}.#{table_name} (#{escaped_target});" end end |