Object::Relation::Schema::DB

Object::Relation::Schema::DB is an Object::Relation database data store schema generation.
Download

Object::Relation::Schema::DB Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Kineticode, Inc.
  • Publisher web site:
  • http://search.cpan.org/~dwheeler/Object-Relation-v0.1.0/lib/Object/Relation/Setup/DB/SQLite.pm

Object::Relation::Schema::DB Tags


Object::Relation::Schema::DB Description

Object::Relation::Schema::DB is an Object::Relation database data store schema generation. Object::Relation::Schema::DB is an Object::Relation database data store schema generation.Synopsis use Object::Relation::Schema; my kbs = Object::Relation::Schema->new; $kbs->write_schema($file_name);This is an abstract base class for the generation and output of a database schema to build a data store for a Object::Relation application. See Object::Relation::Schema for more information and the subclasses of Object::Relation::Schema::DB for database-specific implementations.Naming ConventionsThe naming conventions for database objects are defined by the schema meta classes. See Object::Relation::Meta::Class::Schema and Object::Relation::Meta::Attribute::Schema for the methods that define these names and documentation for the naming conventions.Instance InterfaceInstance Methodsschema_for_class my @sql = $kbs->schema_for_class($class);Returns a list of the SQL statements that can be used to build the tables, indexes constraints, etc. necessary to manage a class in a database. Pass in a Object::Relation::Meta::Class object as the sole argument.sequences_for_class my $sequence_sql = $kbs->sequences_for_class($class);This method takes a class object. By default it returns an empty list (or undef in a scalar context, but don't do that). Subclassses may use it to return a CREATE SEQUENCE statement for the class.tables_for_class my $table_sql = $kbs->tables_for_class($class);This method takes a class object. It returns a CREATE TABLE SQL statement for the class.collection_table my $coll_class = $attribute->collection_of; my $table = $kbs->collection_table($class, $coll_class);For an attribute which represents a collection of objects, for example, attributes which have a has_many relationship, the primary table will not have a column representing the attribute. Instead, another table representing the relationship is created. This method will return the CREATE TABLE statement for that table.format_coll_table my $table = $kbs->collection_table($table, $has_key, $had_key);Called by collection_table(), this method generates the actual CREATE TABLE statement. Pass in the name of the table, the key name of the class that contains the collection, and the key name of the class of objects stored in the collection. It creates a simple table declaration that includes the PRIMARY KEY expression, which is usable by most databases.collection_view my $coll_class = $attribute->collection_of; my $view = $kbs->collection_view($class, $coll_class);For an attribute which represents a collection of objects--for example, attributes that have a has_many relationship--this method returns a CREATE VIEW statement for the table created by the SQL returned by collection_table().format_coll_view my $view = $kbs->collection_view($table, $has_key, $had_key);Called by collection_view(), this method generates the actual CREATE VIEW statement. Pass in the name of the table, the key name of the class that contains the collection, and the key name of the class of objects stored in the collection.start_table my $start_table_sql = $kbs->start_table($class);This method is called by tables_for_class() to generate the opening statement for creating a table.end_table my $end_table_sql = $kbs->end_table($class);This method is called by tables_for_class() to generate the closing statement for creating a table.columns_for_class my @column_sql = $kbs->columns_for_class($class);This method returns all of the columns necessary to represent a class in a table.generate_column my $column_sql = $kbs->generate_column($class, $attr);This method returns the SQL representing a single column declaration in a table, where the column holds data represented by the Object::Relation::Meta::Attribute object passed to the method.column_type my $type = $kbs->column_type($attr);Pass in a Object::Relation::Meta::Attribute::Schema object to get back the column type to be used for the attribute. This implementation simply returns the string "TEXT" for all attributes, but may be overridden in subclasses to return something more appropriate to particular attribute types.column_null my $null_sql = $kbs->column_null($attr);Pass in a Object::Relation::Meta::Attribute::Schema object to get back the null constraint expression for the attribute. Returns "NOT NULL" if the attribute is required, and an empty string if it is not required.column_default my $default_sql = $kbs->column_default($attr);Pass in a Object::Relation::Meta::Attribute::Schema object to get back the default value expression for the column for the attribute. Returns undef (or an empty list) if there is no default value on the column. Otherwise, it returns the default value expression.column_reference my $ref_sql = $kbs->column_reference($attr);Pass in a Object::Relation::Meta::Attribute::Schema object to get back the SQL expression to create a foreign key relationship to another table for the given attribute. Returns undef (or an empty list) if the attribute is not a reference to another object. Otherwise, it returns a simple reference statement of the form "REFERENCES table(id) ON DELETE CASCADE" (where "table" and "CASCADE" may vary). This method may be overridden in subclasses to return undef if they use named foreign key constraints, instead.pk_column my $pk_sql = $kbs->pk_column($class);Returns the SQL statement to create the primary key column for the table for the Object::Relation::Meta::Class::Schema object passed as its sole argument. If the class has a concrete parent class, the primary key column expression will reference the primary key in the parent table. Otherwise, it will just define the primary key for the current class.indexes_for_class my $index_sql = $kbs->indexes_for_class($class);Returns the SQL statements to create all of the indexes for the class described by the Object::Relation::Meta::Class::Schema object passed as the sole argument. All of the index declaration statements will be returned in a single string, each separated by a "n".index_for_attr my $index = $kbs->index_for_attr($class, $attr);Returns the SQL that declares an SQL index. The default implementation here uses the SQL standard index declaration, adding the UNIQUE key word if the attribute is a unique attribute, and using the index_on() method to specify the column to index._collection_indexes my @collection_indexes = $kbs->_collection_indexes($class);For a given class, this method will return all collection indexes for the class.index_on my $column = $kbs->index_on($attr);Returns the name of the column on which an index will be generated for the given Object::Relation::Meta::Attribute::Schema object. Called by index_for_class(). May be overridden in subclasses to enclose the column name in SQL functions and the like.constraints_for_class my $constraint_sql = $kbs->constraints_for_class($class);Returns a list of the SQL statements to create all of the constraints for the class described by the Object::Relation::Meta::Class::Schema object passed as the sole argument.This implementation actually returns undef (or an empty list), but may be overridden in subclasses to return constraint statements.procedures_for_class my $constraint_sql = $kbs->procedures_for_class($class);Returns a list of the SQL statements to create all of the procedures and/or functions for the class described by the Object::Relation::Meta::Class::Schema object passed as the sole argument.This implementation actually returns undef (or an empty list), but may be overridden in subclasses to return procedure declarations.views_for_class my $view_sql = $kbs->views_for_class($class);Returns the SQL statement to create a database view for class described by the Object::Relation::Meta::Class::Schema object passed as the sole argument. Views are the main construct to access the attributes of a class. They will often encapsulate inheritance relationships, so that consumer code does not have to be aware of the inheritance relationship of tables when selecting or modify the contents of an object. They will also often encapsulate the relationship between an object and any other objects it contains ("has-a" relationships) by including all of the attributes of the contained object in the view. This approach makes selecting an object and all of its contained objects very easy to do in a single SELECT statement.view_columns my @view_col_sql = $kbs->view_columns($table, $tables, $wheres, @attrs);Used by the views_for_class() method to generate and return the SQL expressions for all of the columns used in a view. This method may be called recursively to get all of the column names for all of the tables referenced in a view, including parent tables and contained object tables.The arguments are as follows:$table The name of the table for which we're currently defining the columns. This may be used to create JOINs.$tables A reference to an array of all the tables used in the view to the point that view_columns() was called. view_columns may add new table names to this array, so calling code must be sure to include them all in the view.$wheres A reference to an array of all the WHERE statements used in the view to the point that view_columns() was called. view_columns may add new WHERE statements to this array, so calling code must be sure to include them all in the view.@attrs A list of the attributes to that correspond to columns in the table specified by the $table argument.extras_for_class my @sql = $kbs->extras_for_class($class)Returns a list of any extra SQL statements that need to be executed in order to adequately represent a class in the database. By default, there are none, so this method returns none. But subclasses may override it to provide extra functionality. Requirements: · Perl


Object::Relation::Schema::DB Related Software