class Cequel::Schema::TableDescDsl

Attributes

columns[R]
is_compact_storage[R]
is_view[R]
properties[R]
table_name[R]

Public Class Methods

new(table_name) click to toggle source

Initialize a new instance

table_name - The name of the table being described.

# File lib/cequel/schema/table_desc_dsl.rb, line 31
          def initialize(table_name)
  @table_name = table_name
  @columns = []
  @properties = []
  @is_compact_storage = false
  @is_view = false
  @has_part_key = false
end

Public Instance Methods

column(name, type, options = {}) click to toggle source

Describe a column of the table

name - The name of the column. type - The type of the column. Either a `Cequel::Type` or a symbol.

See `Cequel::Type`.

options

:index - name of a secondary index to apply to the column, or
  `true` to infer an index name by convention
# File lib/cequel/schema/table_desc_dsl.rb, line 88
def column(name, type, options = {})
  columns << DataColumn.new(name, type(type),
                            figure_index_name(name, options.fetch(:index, nil)))
end
compact_storage() click to toggle source

Direct that this table use “compact storage”. This is primarily useful for backwards compatibility with legacy CQL2 table schemas.

@return [void]

# File lib/cequel/schema/table_desc_dsl.rb, line 143
def compact_storage
  @is_compact_storage = true
end
eval(&desc_block) click to toggle source

Returns a Table object built by evaluating the provided block.

Yields nothing but block is instance_evaled so it as access to

all the methods of the instance.
# File lib/cequel/schema/table_desc_dsl.rb, line 44
def eval(&desc_block)
  instance_eval(&desc_block)

  table
end
key(name, type, clustering_order = nil) click to toggle source

Describe (one of) the key(s) of the table.

name - The name of the column type - The type of the column. Either a `Cequel::Type` or a symbol.

See `Cequel::Type`.

clustering_order - `:asc` or `:desc`. Only meaningful for cluster

keys. Leave nil for partition keys.
# File lib/cequel/schema/table_desc_dsl.rb, line 69
def key(name, type, clustering_order = nil)
  columns << if has_partition_key?
               ClusteringColumn.new(name, type(type), clustering_order)
             else
               (fail ArgumentError, "Can't set clustering order for partition key #{name}") if clustering_order

               PartitionKey.new(name, type(type))
             end
end
list(name, type) click to toggle source

Describe a column of type list.

name - The name of the column. type - The type of the elements of this column. Either a

`Cequel::Type` or a symbol. See `Cequel::Type`.
# File lib/cequel/schema/table_desc_dsl.rb, line 99
def list(name, type)
  columns << List.new(name, type(type))
end
map(name, key_type, value_type) click to toggle source

Describe a column of type map.

name - The name of the column. key_type - The type of the keys of this column. Either a

`Cequel::Type` or a symbol. See `Cequel::Type`.

value_type - The type of the values of this column. Either a

`Cequel::Type` or a symbol. See `Cequel::Type`.
# File lib/cequel/schema/table_desc_dsl.rb, line 120
def map(name, key_type, value_type)
  columns << Map.new(name, type(key_type), type(value_type))
end
materialized_view() click to toggle source

Indicates that this is a materialized view.

@return [void]

# File lib/cequel/schema/table_desc_dsl.rb, line 151
def materialized_view
  self.is_view = true
end
partition_key(name, type) click to toggle source

Describe (one of) the partition key(s) of the table.

name - The name of the column. type - The type of the column. Either a `Cequel::Type` or a symbol.

See `Cequel::Type`.
# File lib/cequel/schema/table_desc_dsl.rb, line 56
def partition_key(name, type)
  columns <<  PartitionKey.new(name, type(type))
end
set(name, type) click to toggle source

Describe a column of type set.

name - The name of the column. type - The type of the members of this column. Either a

`Cequel::Type` or a symbol. See `Cequel::Type`.
# File lib/cequel/schema/table_desc_dsl.rb, line 109
def set(name, type)
  columns << Set.new(name, type(type))
end
table() click to toggle source
# File lib/cequel/schema/table_desc_dsl.rb, line 155
def table
  Table.new(table_name, is_view).tap do |tab|
    columns.each do |c|
      tab.add_column c
    end
    properties.each do |p|
      tab.add_property p
    end
    tab.compact_storage = is_compact_storage
  end
end
with(name, value) click to toggle source

Describe property of the table.

name - name of property. value - value of property.

See `STORAGE_PROPERTIES` List of storage property names See cassandra.apache.org/doc/cql3/CQL.html#createTableOptions

list of CQL3 table storage properties
# File lib/cequel/schema/table_desc_dsl.rb, line 133
def with(name, value)
  properties << TableProperty.build(name, value)
end

Protected Instance Methods

figure_index_name(column_name, idx_opt) click to toggle source
# File lib/cequel/schema/table_desc_dsl.rb, line 183
def figure_index_name(column_name, idx_opt)
  case idx_opt
  when true
    :"#{table_name}_#{column_name}_idx"
  when false, nil
    nil
  else
    idx_opt
  end
end
has_partition_key?() click to toggle source
# File lib/cequel/schema/table_desc_dsl.rb, line 173
def has_partition_key?
  columns.any?{|c| c.partition_key? }
end
type(type) click to toggle source
# File lib/cequel/schema/table_desc_dsl.rb, line 177
def type(type)
  type = :int if type == :enum

  ::Cequel::Type[type]
end