Class: Cequel::Schema::TableDescDsl
- Inherits:
- BasicObject
- Extended by:
- Util::Forwardable
- Defined in:
- lib/cequel/schema/table_desc_dsl.rb
Overview
Instance Method Summary collapse
-
#column(name, type, options = {}) ⇒ Object
Describe a column of the table.
-
#compact_storage ⇒ void
Direct that this table use “compact storage”.
-
#eval(&desc_block) ⇒ Object
Returns a Table object built by evaluating the provided block.
-
#key(name, type, clustering_order = nil) ⇒ Object
Describe (one of) the key(s) of the table.
-
#list(name, type) ⇒ Object
Describe a column of type list.
-
#map(name, key_type, value_type) ⇒ Object
Describe a column of type map.
-
#materialized_view ⇒ void
Indicates that this is a materialized view.
-
#partition_key(name, type) ⇒ Object
Describe (one of) the partition key(s) of the table.
-
#set(name, type) ⇒ Object
Describe a column of type set.
- #table ⇒ Object
-
#with(name, value) ⇒ Object
Describe property of the table.
Methods included from Util::Forwardable
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
89 90 91 92 |
# File 'lib/cequel/schema/table_desc_dsl.rb', line 89 def column(name, type, = {}) columns << DataColumn.new(name, type(type), figure_index_name(name, .fetch(:index, nil))) end |
#compact_storage ⇒ void
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.
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.
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.
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`.
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`.
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_view ⇒ void
This method returns an undefined value.
Indicates that this is a materialized view.
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`.
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`.
110 111 112 |
# File 'lib/cequel/schema/table_desc_dsl.rb', line 110 def set(name, type) columns << Set.new(name, type(type)) end |
#table ⇒ Object
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
134 135 136 |
# File 'lib/cequel/schema/table_desc_dsl.rb', line 134 def with(name, value) properties << TableProperty.build(name, value) end |