class Cequel::Schema::Table
An object representation of a CQL3 table schema.
@see Keyspace#read_table
Attributes
@return [Array<ClusteringColumn>] clustering columns defined on the
table
@return [Array<Column>] all columns defined on the table
@return [Boolean] `true` if this table is configured with compact
storage
@return [Array<DataColumn,CollectionColumn>] data columns and
collection columns defined on the table
@return [Symbol] the name of the table
@return [Array<PartitionKey>] partition key columns defined on the
table
@return [Hash] storage properties defined on the table
Public Class Methods
@param name [Symbol] the name of the table @api private
# File lib/cequel/schema/table.rb, line 41 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
Public Instance Methods
Add a column descriptor to this table descriptor.
column_desc - Descriptor of column to add. Can be PartitionKey
,
ClusteringColumn, DataColumn, List, Set, or Map.
# File lib/cequel/schema/table.rb, line 59 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 a property to this table descriptor
property_desc - A `TableProperty` describing one property of this table.
# File lib/cequel/schema/table.rb, line 78 def add_property(property_desc) properties[property_desc.name] = property_desc end
@param name [Symbol] name of clustering column to look up @return [ClusteringColumn] clustering column with given name
# File lib/cequel/schema/table.rb, line 171 def clustering_column(name) clustering_columns.find { |column| column.name == name } end
@return [Integer] number of clustering columns
# File lib/cequel/schema/table.rb, line 155 def clustering_column_count clustering_columns.length end
@return [Array<Symbol>] names of clustering columns
# File lib/cequel/schema/table.rb, line 148 def clustering_column_names clustering_columns.map { |key| key.name } end
@param name [Symbol] name of column to look up @return [Column] column defined on table with given name
# File lib/cequel/schema/table.rb, line 87 def column(name) columns_by_name[name.to_sym] end
@return [Array<Symbol>] the names of all columns
# File lib/cequel/schema/table.rb, line 99 def column_names columns_by_name.keys end
@return [Boolean] `true` if this table uses compact storage
# File lib/cequel/schema/table.rb, line 196 def compact_storage? !!@compact_storage end
@param name [Symbol] name of data column to look up @return [DataColumn,CollectionColumn] data column or collection column
with given name
# File lib/cequel/schema/table.rb, line 180 def data_column(name) name = name.to_sym data_columns.find { |column| column.name == name } end
Returns true iff this table has the specified column name.
# File lib/cequel/schema/table.rb, line 93 def has_column?(name) columns_by_name.has_key?(name.to_sym) end
Returns true iff this table descriptor currently has at least one partition key defined.
# File lib/cequel/schema/table.rb, line 141 def has_partition_key? partition_key_columns.any? end
@return [Integer] total number of key columns
# File lib/cequel/schema/table.rb, line 121 def key_column_count key_columns.length end
@return [Array<Symbol>] names of all key columns (partition +
clustering)
# File lib/cequel/schema/table.rb, line 114 def key_column_names key_columns.map { |key| key.name } end
@return [Array<Column>] all key columns (partition + clustering)
# File lib/cequel/schema/table.rb, line 106 def key_columns partition_key_columns + clustering_columns end
@return [Boolean] `true` when this table is a materialized view
# File lib/cequel/schema/table.rb, line 50 def materialized_view? @is_view end
@param name [Symbol] name of partition key column to look up @return [PartitionKey] partition key column with given name
# File lib/cequel/schema/table.rb, line 163 def partition_key(name) partition_key_columns.find { |column| column.name == name } end
@return [Integer] number of partition key columns
# File lib/cequel/schema/table.rb, line 135 def partition_key_column_count partition_key_columns.length end
@return [Array<Symbol>] names of partition key columns
# File lib/cequel/schema/table.rb, line 128 def partition_key_column_names partition_key_columns.map { |key| key.name } end
@param name [Symbol] name of property to look up @return [TableProperty] property as defined on table
# File lib/cequel/schema/table.rb, line 189 def property(name) properties.fetch(name, null_table_property).value end
Protected Instance Methods
# File lib/cequel/schema/table.rb, line 210 def null_table_property @@null_table_property ||= Class.new do def value; nil; end def name; nil; end end.new end
# File lib/cequel/schema/table.rb, line 204 def type(type) type = type.kind if type.respond_to?(:kind) ::Cequel::Type[type] end
# File lib/cequel/schema/table.rb, line 212 def value; nil; end