Class: Cequel::Schema::Table
- Inherits:
-
Object
- Object
- Cequel::Schema::Table
- Defined in:
- lib/cequel/schema/table.rb
Overview
An object representation of a CQL3 table schema.
Instance Attribute Summary collapse
-
#clustering_columns ⇒ Array<ClusteringColumn>
readonly
Clustering columns defined on the table.
-
#columns ⇒ Array<Column>
readonly
All columns defined on the table.
-
#compact_storage ⇒ Boolean
writeonly
‘true` if this table is configured with compact storage.
-
#data_columns ⇒ Array<DataColumn,CollectionColumn>
readonly
Data columns and collection columns defined on the table.
-
#name ⇒ Symbol
readonly
The name of the table.
-
#partition_key_columns ⇒ Array<PartitionKey>
readonly
Partition key columns defined on the table.
-
#properties ⇒ Hash
readonly
Storage properties defined on the table.
Instance Method Summary collapse
-
#add_column(column_desc) ⇒ Object
Add a column descriptor to this table descriptor.
-
#add_property(property_desc) ⇒ Object
Add a property to this table descriptor.
-
#clustering_column(name) ⇒ ClusteringColumn
Clustering column with given name.
-
#clustering_column_count ⇒ Integer
Number of clustering columns.
-
#clustering_column_names ⇒ Array<Symbol>
Names of clustering columns.
-
#column(name) ⇒ Column
Column defined on table with given name.
-
#column_names ⇒ Array<Symbol>
The names of all columns.
-
#compact_storage? ⇒ Boolean
‘true` if this table uses compact storage.
-
#data_column(name) ⇒ DataColumn, CollectionColumn
Data column or collection column with given name.
-
#has_column?(name) ⇒ Boolean
Returns true iff this table has the specified column name.
-
#has_partition_key? ⇒ Boolean
Returns true iff this table descriptor currently has at least one partition key defined.
-
#initialize(name, is_view = false) ⇒ Table
constructor
private
A new instance of Table.
-
#key_column_count ⇒ Integer
Total number of key columns.
-
#key_column_names ⇒ Array<Symbol>
Names of all key columns (partition + clustering).
-
#key_columns ⇒ Array<Column>
All key columns (partition + clustering).
-
#materialized_view? ⇒ Boolean
‘true` when this table is a materialized view.
-
#partition_key(name) ⇒ PartitionKey
Partition key column with given name.
-
#partition_key_column_count ⇒ Integer
Number of partition key columns.
-
#partition_key_column_names ⇒ Array<Symbol>
Names of partition key columns.
-
#property(name) ⇒ TableProperty
Property as defined on table.
Constructor Details
#initialize(name, is_view = false) ⇒ Table
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Table.
42 43 44 45 46 47 48 |
# File 'lib/cequel/schema/table.rb', line 42 def initialize(name, is_view=false) @name = name.to_sym @is_view = is_view @partition_key_columns, @clustering_columns, @data_columns = [], [], [] @columns, @columns_by_name = [], {} @properties = ActiveSupport::HashWithIndifferentAccess.new end |
Instance Attribute Details
#clustering_columns ⇒ Array<ClusteringColumn> (readonly)
Returns clustering columns defined on the table.
25 26 27 |
# File 'lib/cequel/schema/table.rb', line 25 def clustering_columns @clustering_columns end |
#columns ⇒ Array<Column> (readonly)
Returns all columns defined on the table.
17 18 19 |
# File 'lib/cequel/schema/table.rb', line 17 def columns @columns end |
#compact_storage=(value) ⇒ Boolean (writeonly)
Returns ‘true` if this table is configured with compact storage.
36 37 38 |
# File 'lib/cequel/schema/table.rb', line 36 def compact_storage=(value) @compact_storage = value end |
#data_columns ⇒ Array<DataColumn,CollectionColumn> (readonly)
Returns data columns and collection columns defined on the table.
29 30 31 |
# File 'lib/cequel/schema/table.rb', line 29 def data_columns @data_columns end |
#name ⇒ Symbol (readonly)
Returns the name of the table.
14 15 16 |
# File 'lib/cequel/schema/table.rb', line 14 def name @name end |
#partition_key_columns ⇒ Array<PartitionKey> (readonly)
Returns partition key columns defined on the table.
21 22 23 |
# File 'lib/cequel/schema/table.rb', line 21 def partition_key_columns @partition_key_columns end |
#properties ⇒ Hash (readonly)
Returns storage properties defined on the table.
32 33 34 |
# File 'lib/cequel/schema/table.rb', line 32 def properties @properties end |
Instance Method Details
#add_column(column_desc) ⇒ Object
Add a column descriptor to this table descriptor.
column_desc - Descriptor of column to add. Can be PartitionKey,
ClusteringColumn, DataColumn, List, Set, or Map.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cequel/schema/table.rb', line 60 def add_column(column_desc) column_flavor = case column_desc when PartitionKey @partition_key_columns when ClusteringColumn @clustering_columns else @data_columns end column_flavor << column_desc columns << column_desc columns_by_name[column_desc.name] = column_desc end |
#add_property(property_desc) ⇒ Object
Add a property to this table descriptor
property_desc - A ‘TableProperty` describing one property of this table.
79 80 81 |
# File 'lib/cequel/schema/table.rb', line 79 def add_property(property_desc) properties[property_desc.name] = property_desc end |
#clustering_column(name) ⇒ ClusteringColumn
Returns clustering column with given name.
172 173 174 |
# File 'lib/cequel/schema/table.rb', line 172 def clustering_column(name) clustering_columns.find { |column| column.name == name } end |
#clustering_column_count ⇒ Integer
Returns number of clustering columns.
156 157 158 |
# File 'lib/cequel/schema/table.rb', line 156 def clustering_column_count clustering_columns.length end |
#clustering_column_names ⇒ Array<Symbol>
Returns names of clustering columns.
149 150 151 |
# File 'lib/cequel/schema/table.rb', line 149 def clustering_column_names clustering_columns.map { |key| key.name } end |
#column(name) ⇒ Column
Returns column defined on table with given name.
88 89 90 |
# File 'lib/cequel/schema/table.rb', line 88 def column(name) columns_by_name[name.to_sym] end |
#column_names ⇒ Array<Symbol>
Returns the names of all columns.
100 101 102 |
# File 'lib/cequel/schema/table.rb', line 100 def column_names columns_by_name.keys end |
#compact_storage? ⇒ Boolean
Returns ‘true` if this table uses compact storage.
197 198 199 |
# File 'lib/cequel/schema/table.rb', line 197 def compact_storage? !!@compact_storage end |
#data_column(name) ⇒ DataColumn, CollectionColumn
Returns data column or collection column with given name.
181 182 183 184 |
# File 'lib/cequel/schema/table.rb', line 181 def data_column(name) name = name.to_sym data_columns.find { |column| column.name == name } end |
#has_column?(name) ⇒ Boolean
Returns true iff this table has the specified column name.
94 95 96 |
# File 'lib/cequel/schema/table.rb', line 94 def has_column?(name) columns_by_name.has_key?(name.to_sym) end |
#has_partition_key? ⇒ Boolean
Returns true iff this table descriptor currently has at least one partition key defined.
142 143 144 |
# File 'lib/cequel/schema/table.rb', line 142 def has_partition_key? partition_key_columns.any? end |
#key_column_count ⇒ Integer
Returns total number of key columns.
122 123 124 |
# File 'lib/cequel/schema/table.rb', line 122 def key_column_count key_columns.length end |
#key_column_names ⇒ Array<Symbol>
Returns names of all key columns (partition + clustering).
115 116 117 |
# File 'lib/cequel/schema/table.rb', line 115 def key_column_names key_columns.map { |key| key.name } end |
#key_columns ⇒ Array<Column>
Returns all key columns (partition + clustering).
107 108 109 |
# File 'lib/cequel/schema/table.rb', line 107 def key_columns partition_key_columns + clustering_columns end |
#materialized_view? ⇒ Boolean
Returns ‘true` when this table is a materialized view.
51 52 53 |
# File 'lib/cequel/schema/table.rb', line 51 def materialized_view? @is_view end |
#partition_key(name) ⇒ PartitionKey
Returns partition key column with given name.
164 165 166 |
# File 'lib/cequel/schema/table.rb', line 164 def partition_key(name) partition_key_columns.find { |column| column.name == name } end |
#partition_key_column_count ⇒ Integer
Returns number of partition key columns.
136 137 138 |
# File 'lib/cequel/schema/table.rb', line 136 def partition_key_column_count partition_key_columns.length end |
#partition_key_column_names ⇒ Array<Symbol>
Returns names of partition key columns.
129 130 131 |
# File 'lib/cequel/schema/table.rb', line 129 def partition_key_column_names partition_key_columns.map { |key| key.name } end |
#property(name) ⇒ TableProperty
Returns property as defined on table.
190 191 192 |
# File 'lib/cequel/schema/table.rb', line 190 def property(name) properties.fetch(name, null_table_property).value end |