Class: Cequel::Schema::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/cequel/schema/table.rb

Overview

An object representation of a CQL3 table schema.

See Also:

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • name (Symbol)

    the name of the table

Since:

  • 1.0.0



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_columnsArray<ClusteringColumn> (readonly)

Returns clustering columns defined on the table.

Returns:

Since:

  • 1.0.0



25
26
27
# File 'lib/cequel/schema/table.rb', line 25

def clustering_columns
  @clustering_columns
end

#columnsArray<Column> (readonly)

Returns all columns defined on the table.

Returns:

  • (Array<Column>)

    all columns defined on the table

Since:

  • 1.0.0



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.

Returns:

  • (Boolean)

    ‘true` if this table is configured with compact storage

Since:

  • 1.0.0



36
37
38
# File 'lib/cequel/schema/table.rb', line 36

def compact_storage=(value)
  @compact_storage = value
end

#data_columnsArray<DataColumn,CollectionColumn> (readonly)

Returns data columns and collection columns defined on the table.

Returns:

Since:

  • 1.0.0



29
30
31
# File 'lib/cequel/schema/table.rb', line 29

def data_columns
  @data_columns
end

#nameSymbol (readonly)

Returns the name of the table.

Returns:

  • (Symbol)

    the name of the table

Since:

  • 1.0.0



14
15
16
# File 'lib/cequel/schema/table.rb', line 14

def name
  @name
end

#partition_key_columnsArray<PartitionKey> (readonly)

Returns partition key columns defined on the table.

Returns:

  • (Array<PartitionKey>)

    partition key columns defined on the table

Since:

  • 1.0.0



21
22
23
# File 'lib/cequel/schema/table.rb', line 21

def partition_key_columns
  @partition_key_columns
end

#propertiesHash (readonly)

Returns storage properties defined on the table.

Returns:

  • (Hash)

    storage properties defined on the table

Since:

  • 1.0.0



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.

Since:

  • 1.0.0



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.

Since:

  • 1.0.0



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.

Parameters:

  • name (Symbol)

    name of clustering column to look up

Returns:

Since:

  • 1.0.0



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_countInteger

Returns number of clustering columns.

Returns:

  • (Integer)

    number of clustering columns

Since:

  • 1.0.0



156
157
158
# File 'lib/cequel/schema/table.rb', line 156

def clustering_column_count
  clustering_columns.length
end

#clustering_column_namesArray<Symbol>

Returns names of clustering columns.

Returns:

  • (Array<Symbol>)

    names of clustering columns

Since:

  • 1.0.0



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.

Parameters:

  • name (Symbol)

    name of column to look up

Returns:

  • (Column)

    column defined on table with given name

Since:

  • 1.0.0



88
89
90
# File 'lib/cequel/schema/table.rb', line 88

def column(name)
  columns_by_name[name.to_sym]
end

#column_namesArray<Symbol>

Returns the names of all columns.

Returns:

  • (Array<Symbol>)

    the names of all columns

Since:

  • 1.0.0



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.

Returns:

  • (Boolean)

    ‘true` if this table uses compact storage

Since:

  • 1.0.0



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.

Parameters:

  • name (Symbol)

    name of data column to look up

Returns:

Since:

  • 1.0.0



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.

Returns:

  • (Boolean)

Since:

  • 1.0.0



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.

Returns:

  • (Boolean)

Since:

  • 1.0.0



142
143
144
# File 'lib/cequel/schema/table.rb', line 142

def has_partition_key?
  partition_key_columns.any?
end

#key_column_countInteger

Returns total number of key columns.

Returns:

  • (Integer)

    total number of key columns

Since:

  • 1.0.0



122
123
124
# File 'lib/cequel/schema/table.rb', line 122

def key_column_count
  key_columns.length
end

#key_column_namesArray<Symbol>

Returns names of all key columns (partition + clustering).

Returns:

  • (Array<Symbol>)

    names of all key columns (partition + clustering)

Since:

  • 1.0.0



115
116
117
# File 'lib/cequel/schema/table.rb', line 115

def key_column_names
  key_columns.map { |key| key.name }
end

#key_columnsArray<Column>

Returns all key columns (partition + clustering).

Returns:

  • (Array<Column>)

    all key columns (partition + clustering)

Since:

  • 1.0.0



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.

Returns:

  • (Boolean)

    ‘true` when this table is a materialized view

Since:

  • 1.0.0



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.

Parameters:

  • name (Symbol)

    name of partition key column to look up

Returns:

Since:

  • 1.0.0



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_countInteger

Returns number of partition key columns.

Returns:

  • (Integer)

    number of partition key columns

Since:

  • 1.0.0



136
137
138
# File 'lib/cequel/schema/table.rb', line 136

def partition_key_column_count
  partition_key_columns.length
end

#partition_key_column_namesArray<Symbol>

Returns names of partition key columns.

Returns:

  • (Array<Symbol>)

    names of partition key columns

Since:

  • 1.0.0



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.

Parameters:

  • name (Symbol)

    name of property to look up

Returns:

Since:

  • 1.0.0



190
191
192
# File 'lib/cequel/schema/table.rb', line 190

def property(name)
  properties.fetch(name, null_table_property).value
end