Class: Cequel::Schema::TableDescDsl

Inherits:
BasicObject
Extended by:
Util::Forwardable
Defined in:
lib/cequel/schema/table_desc_dsl.rb

Overview

Since:

  • 1.0.0

Instance Method Summary collapse

Methods included from Util::Forwardable

delegate

Instance Method Details

#column(name, type, options = {}) ⇒ Object

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

Since:

  • 1.0.0



89
90
91
92
# File 'lib/cequel/schema/table_desc_dsl.rb', line 89

def column(name, type, options = {})
  columns << DataColumn.new(name, type(type),
                            figure_index_name(name, options.fetch(:index, nil)))
end

#compact_storagevoid

This method returns an undefined value.

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

Since:

  • 1.0.0



144
145
146
# File 'lib/cequel/schema/table_desc_dsl.rb', line 144

def compact_storage
  @is_compact_storage = true
end

#eval(&desc_block) ⇒ Object

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.

Since:

  • 1.0.0



45
46
47
48
49
# File 'lib/cequel/schema/table_desc_dsl.rb', line 45

def eval(&desc_block)
  instance_eval(&desc_block)

  table
end

#key(name, type, clustering_order = nil) ⇒ Object

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.

Since:

  • 1.0.0



70
71
72
73
74
75
76
77
78
# File 'lib/cequel/schema/table_desc_dsl.rb', line 70

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) ⇒ Object

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`.

Since:

  • 1.0.0



100
101
102
# File 'lib/cequel/schema/table_desc_dsl.rb', line 100

def list(name, type)
  columns << List.new(name, type(type))
end

#map(name, key_type, value_type) ⇒ Object

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`.

Since:

  • 1.0.0



121
122
123
# File 'lib/cequel/schema/table_desc_dsl.rb', line 121

def map(name, key_type, value_type)
  columns << Map.new(name, type(key_type), type(value_type))
end

#materialized_viewvoid

This method returns an undefined value.

Indicates that this is a materialized view.

Since:

  • 1.0.0



152
153
154
# File 'lib/cequel/schema/table_desc_dsl.rb', line 152

def materialized_view
  self.is_view = true
end

#partition_key(name, type) ⇒ Object

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`.

Since:

  • 1.0.0



57
58
59
# File 'lib/cequel/schema/table_desc_dsl.rb', line 57

def partition_key(name, type)
  columns <<  PartitionKey.new(name, type(type))
end

#set(name, type) ⇒ Object

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`.

Since:

  • 1.0.0



110
111
112
# File 'lib/cequel/schema/table_desc_dsl.rb', line 110

def set(name, type)
  columns << Set.new(name, type(type))
end

#tableObject

Since:

  • 1.0.0



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/cequel/schema/table_desc_dsl.rb', line 156

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) ⇒ Object

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

Since:

  • 1.0.0



134
135
136
# File 'lib/cequel/schema/table_desc_dsl.rb', line 134

def with(name, value)
  properties << TableProperty.build(name, value)
end