Class Innodb::RecordDescriber
In: lib/innodb/record_describer.rb
Parent: Object

A class to describe record layouts for InnoDB indexes. Designed to be usable in two different ways: statically built and dynamically built. Note that in both cases, the order that statements are encountered is critical. Columns must be added to the key and row structures in the correct order.

STATIC USAGE

Static building is useful for building a custom describer for any index and looks like the following:

To describe the SQL syntax:

  CREATE TABLE my_table (
    id BIGINT NOT NULL,
    name VARCHAR(100) NOT NULL,
    age INT UNSIGNED,
    PRIMARY KEY (id)
  );

The clustered key would require a class like:

  class MyTableClusteredDescriber < Innodb::RecordDescriber
    type :clustered
    key "id", :BIGINT, :UNSIGNED, :NOT_NULL
    row "name", "VARCHAR(100)", :NOT_NULL
    row "age", :INT, :UNSIGNED
  end

It can then be instantiated as usual:

  my_table_clustered = MyTableClusteredDescriber.new

All statically-defined type, key, and row information will be copied into the instance when it is initialized. Once initialized, the instance can be additionally used dynamically, as per below. (A dynamic class is just the same as a static class that is empty.)

Note that since InnoDB works in terms of indexes individually, a new class must be created for each index.

DYNAMIC USAGE

If a record describer needs to be built based on runtime information, such as index descriptions from a live data dictionary, instances can be built dynamically. For the same table above, this would require:

  my_table_clustered = Innodb::RecordDescriber.new
  my_table_clustered.type = :clustered
  my_table_clustered.key "id", :BIGINT, :UNSIGNED, :NOT_NULL
  my_table_clustered.row "name", "VARCHAR(100)", :NOT_NULL
  my_table_clustered.row "age", :INT, :UNSIGNED

Methods

add_field   add_static_field   field_names   generate_class   key   key   new   row   row   static_description   type   type  

Attributes

description  [RW] 

Public Class methods

An internal method wrapped with ‘key’ and ‘row’ helpers.

A ‘key’ method to be used from the DSL.

A ‘row’ method to be used from the DSL.

Internal method to initialize the class‘s instance variable on access.

A ‘type’ method to be used from the DSL.

Public Instance methods

An internal method wrapped with ‘key’ and ‘row’ helpers.

Add a key column to the record description.

Add a row (non-key) column to the record description.

Set the type of this record (:clustered or :secondary).

[Validate]