Class: Cassandra::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra/index.rb

Overview

Represents an index on a cassandra table

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#kindSymbol (readonly)



27
28
29
# File 'lib/cassandra/index.rb', line 27

def kind
  @kind
end

#nameString (readonly)



25
26
27
# File 'lib/cassandra/index.rb', line 25

def name
  @name
end

#optionsHash (readonly)



31
32
33
# File 'lib/cassandra/index.rb', line 31

def options
  @options
end

#tableCassandra::Table (readonly)



23
24
25
# File 'lib/cassandra/index.rb', line 23

def table
  @table
end

#targetString (readonly)



29
30
31
# File 'lib/cassandra/index.rb', line 29

def target
  @target
end

Instance Method Details

#custom_class_nameString



61
62
63
# File 'lib/cassandra/index.rb', line 61

def custom_class_name
  @options['class_name']
end

#custom_index?Boolean



56
57
58
# File 'lib/cassandra/index.rb', line 56

def custom_index?
  !@options['class_name'].nil?
end

#to_cqlString



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