Module: Cequel::Record::Schema::ClassMethods
- Extended by:
- Util::Forwardable
- Defined in:
- lib/cequel/record/schema.rb
Overview
Methods available on Cequel::Record class singletons to introspect and modify the schema defined in the database
Instance Attribute Summary collapse
-
#clustering_columns ⇒ Array<ClusteringColumn>
readonly
Clustering columns defined on the table.
-
#column_names ⇒ Array<Symbol>
readonly
The names of all columns.
-
#columns ⇒ Array<Column>
readonly
All columns defined on the table.
-
#key_column_names ⇒ Array<Symbol>
readonly
Names of all key columns (partition + clustering).
-
#key_columns ⇒ Array<Column>
readonly
All key columns (partition + clustering).
-
#partition_key_column_names ⇒ Array<Symbol>
readonly
Names of partition key columns.
-
#partition_key_columns ⇒ Array<PartitionKey>
readonly
Partition key columns defined on the table.
Instance Method Summary collapse
-
#compact_storage? ⇒ Boolean
‘true` if this table uses compact storage.
-
#read_schema ⇒ Schema::Table
Read the current state of this record’s table in Cassandra from the database.
-
#reflect_on_column(name) ⇒ Column
Column defined on table with given name.
-
#synchronize_schema ⇒ void
Read the current schema assigned to this record’s table from Cassandra, and make any necessary modifications (including creating the table for the first time) so that it matches the schema defined in the record definition.
-
#table_schema ⇒ Schema::Table
The schema as defined by the columns specified in the class definition.
Methods included from Util::Forwardable
Instance Attribute Details
#clustering_columns ⇒ Array<ClusteringColumn> (readonly)
Returns clustering columns defined on the table.
63 64 65 66 |
# File 'lib/cequel/record/schema.rb', line 63 def_delegators :table_schema, :columns, :column_names, :key_columns, :key_column_names, :partition_key_columns, :partition_key_column_names, :clustering_columns, :compact_storage? |
#column_names ⇒ Array<Symbol> (readonly)
Returns the names of all columns.
63 64 65 66 |
# File 'lib/cequel/record/schema.rb', line 63 def_delegators :table_schema, :columns, :column_names, :key_columns, :key_column_names, :partition_key_columns, :partition_key_column_names, :clustering_columns, :compact_storage? |
#columns ⇒ Array<Column> (readonly)
Returns all columns defined on the table.
63 64 65 66 |
# File 'lib/cequel/record/schema.rb', line 63 def_delegators :table_schema, :columns, :column_names, :key_columns, :key_column_names, :partition_key_columns, :partition_key_column_names, :clustering_columns, :compact_storage? |
#key_column_names ⇒ Array<Symbol> (readonly)
Returns names of all key columns (partition + clustering).
63 64 65 66 |
# File 'lib/cequel/record/schema.rb', line 63 def_delegators :table_schema, :columns, :column_names, :key_columns, :key_column_names, :partition_key_columns, :partition_key_column_names, :clustering_columns, :compact_storage? |
#key_columns ⇒ Array<Column> (readonly)
Returns all key columns (partition + clustering).
63 64 65 66 |
# File 'lib/cequel/record/schema.rb', line 63 def_delegators :table_schema, :columns, :column_names, :key_columns, :key_column_names, :partition_key_columns, :partition_key_column_names, :clustering_columns, :compact_storage? |
#partition_key_column_names ⇒ Array<Symbol> (readonly)
Returns names of partition key columns.
63 64 65 66 |
# File 'lib/cequel/record/schema.rb', line 63 def_delegators :table_schema, :columns, :column_names, :key_columns, :key_column_names, :partition_key_columns, :partition_key_column_names, :clustering_columns, :compact_storage? |
#partition_key_columns ⇒ Array<PartitionKey> (readonly)
Returns partition key columns defined on the table.
63 64 65 66 |
# File 'lib/cequel/record/schema.rb', line 63 def_delegators :table_schema, :columns, :column_names, :key_columns, :key_column_names, :partition_key_columns, :partition_key_column_names, :clustering_columns, :compact_storage? |
Instance Method Details
#compact_storage? ⇒ Boolean
Returns ‘true` if this table uses compact storage.
63 64 65 66 |
# File 'lib/cequel/record/schema.rb', line 63 def_delegators :table_schema, :columns, :column_names, :key_columns, :key_column_names, :partition_key_columns, :partition_key_column_names, :clustering_columns, :compact_storage? |
#read_schema ⇒ Schema::Table
Read the current state of this record’s table in Cassandra from the database.
110 111 112 |
# File 'lib/cequel/record/schema.rb', line 110 def read_schema table_reader.read end |
#reflect_on_column(name) ⇒ Column
Returns column defined on table with given name.
71 |
# File 'lib/cequel/record/schema.rb', line 71 def_delegator :table_schema, :column, :reflect_on_column |
#synchronize_schema ⇒ void
This method returns an undefined value.
Read the current schema assigned to this record’s table from Cassandra, and make any necessary modifications (including creating the table for the first time) so that it matches the schema defined in the record definition
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cequel/record/schema.rb', line 82 def synchronize_schema fail MissingTableNameError unless table_name patch = begin existing_table_descriptor = Cequel::Schema::TableReader.read(connection, table_name) return if existing_table_descriptor.materialized_view? Cequel::Schema::TableDiffer.new(existing_table_descriptor, table_schema) .call rescue NoSuchTableError Cequel::Schema::TableWriter.new(table_schema) end patch.statements.each { |stmt| connection.execute(stmt) } end |
#table_schema ⇒ Schema::Table
Returns the schema as defined by the columns specified in the class definition.
118 119 120 |
# File 'lib/cequel/record/schema.rb', line 118 def table_schema dsl.table end |