Module: Cequel::Record::Schema::ClassMethods

Extended by:
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

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clustering_columnsArray<ClusteringColumn> (readonly)

Returns clustering columns defined on the table.

Returns:

  • (Array<ClusteringColumn>)

    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_namesArray<Symbol> (readonly)

Returns the names of all columns.

Returns:

  • (Array<Symbol>)

    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?

#columnsArray<Column> (readonly)

Returns all columns defined on the table.

Returns:

  • (Array<Column>)

    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_namesArray<Symbol> (readonly)

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

Returns:

  • (Array<Symbol>)

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

Returns all key columns (partition + clustering).

Returns:

  • (Array<Column>)

    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_namesArray<Symbol> (readonly)

Returns names of partition key columns.

Returns:

  • (Array<Symbol>)

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

Returns partition key columns defined on the table.

Returns:

  • (Array<PartitionKey>)

    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.

Returns:

  • (Boolean)

    ‘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_schemaSchema::Table

Read the current state of this record’s table in Cassandra from the database.

Returns:

  • (Schema::Table)

    the current schema assigned to this record’s table in the database

Since:

  • 1.0.0



94
95
96
97
98
# File 'lib/cequel/record/schema.rb', line 94

def read_schema
  fail MissingTableNameError unless table_name

  connection.schema.read_table(table_name)
end

#reflect_on_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



71
# File 'lib/cequel/record/schema.rb', line 71

def_delegator :table_schema, :column, :reflect_on_column

#synchronize_schemavoid

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

Since:

  • 1.0.0



82
83
84
85
# File 'lib/cequel/record/schema.rb', line 82

def synchronize_schema
  Cequel::Schema::TableSynchronizer
    .apply(connection, read_schema, table_schema)
end

#table_schemaSchema::Table

Returns the schema as defined by the columns specified in the class definition.

Returns:

  • (Schema::Table)

    the schema as defined by the columns specified in the class definition

Since:

  • 1.0.0



104
105
106
# File 'lib/cequel/record/schema.rb', line 104

def table_schema
  @table_schema ||= Cequel::Schema::Table.new(table_name)
end