Object::Relation::Schema::DB::Pg

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

Object::Relation::Schema::DB::Pg 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::Pg Tags


Object::Relation::Schema::DB::Pg Description

Object::Relation::Schema::DB::Pg is an Object::Relation PostgreSQL data store schema generation. Synopsis use Object::Relation::Schema; my $kbs = Object::Relation::Schema->new; $kbs->generate_to_file($file_name);This module generates and outputs to a file the schema information necessary to create a PostgreSQL data store for a Object::Relation application. See Object::Relation::Schema and Object::Relation::Schema::DB for more information.Instance InterfaceInstance Methodssequences_for_class my @sequence_sql = $kbs->sequences_for_class($class);This method takes a class object and returns a CREATE SEQUENCE statement for the class if it has no parent classes, as well as sequences for any collections that the class contains.format_coll_table my $table = $kbs->collection_table($table, $has_key, $had_key);This method overrides that in the parent class in order not to have the primary key embedded in the table declaration. This is because we want named primary keys in PostgreSQL.column_type my $type = $kbs->column_type($attr);Pass in a Object::Relation::Meta::Attribute::Schema object to get back the PostgreSQL column type to be used for the attribute. The column types are optimized for the best correspondence between the attribute types and the types supported by PostgreSQL, plus data domains where appropriate (e.g., the "state" column type is defined by a data domain defined by a statement returned by setup_code()).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 no concrete parent class, the primary key column expression will set up a DEFAULT statement to get its value from the sequence created for the class. Otherwise, it will be be a simple column declaration. The primary key constraint is actually returned by constraints_for_class(), and so is not included in the expression returned by pk_column().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. Overrides the parent method to return PostgreSQL-specific default expressions where appropriate (e.g., for boolean) columns.column_reference my $ref_sql = $kbs->column_reference($attr);Overrides the parent method to return undef (or an empty list). This is because the column foreign key constraints are named and returned by constraints_for_class(), instead.index_for_attr my $index = $kbs->index_for_attr($class, $attr);Returns the SQL that declares an SQL index. This implementation overrides that in Object::Relation::Schema::DB to change it to a partial unique index or to remove the UNIQUE keyword if the attribute is unique but not distinct. The difference is that a unique attribute is unique only relative to the state attribute. A unique attribute can have more than one instance of a given value as long as no more than one of them also has a state greater than -1. In PostgreSQL, this is handled by a partial unique index if the attribute and the state attribute are in the same table, or by triggers if they are in different tables (due to inheritance).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() in the parent class. Overridden here to wrap the name in the PostgreSQL LOWER() function when the data type is a string.constraints_for_class my @constraints = $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.The constraint statements returned may include one or more of the following:A primary key constraint.A foreign key constraint from the primary key column to the table for a concrete parent class.Foreign key constraints to the tables for contained (referenced) objects."Once triggers", which prevent a value from being changed in a column after the first time it has been set to a non-NULL value."Unique triggers", which prevent a column from having two rows with the same value. Only applies when the state column is in a parent table, because otherwise this constraint is actually handled by a partial unique index.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.once_triggers_sql my $once_triggers_sql_body = $kbs->once_triggers_sql( $key, $attr, $table, $constraint, );This method is called by once_triggers() to generate database specific rules, functions, triggers, etc., to ensure that a column, once set to a non-null value, can never be changed.unique_triggers my @unique_triggers = $kbs->unique_triggers($class);Returns the PostgreSQL triggers to validate the values of any "unique" attributes, wherein the attribute is in a different class than the state attribute. Unique attributes in the same class as the state attribute are handled by a partial unique index. If the class has no unique attributes unique_triggers() will return an empty list.Called by constraints_for_class().create_trigger_for_table my $trigger = $kbs->create_trigger_for_table( $trigger_name, $type, $table, $when, $func, );Given a trigger name and a table name, returns a CREATE TRIGGER statement which will execute the named trigger before any row is updated/inserted in the table. The $type should be "UPDATE" or "INSERT". $when defaults to "BEFORE". If $func is not passed, the name of the trigger will be used for the name of the function. All other arguments are required.insert_for_class my $insert_rule_sql = $kbs->insert_for_class($class);Returns a PostgreSQL RULE that manages INSERT statements executed against the view for the class. The rule ensures that the INSERT statement updates the table for the class as well as any parent classes. Extended and mediated objects are also inserted or updated as appropriate, but other contained objects are ignored, and should be inserted or updated separately.update_for_class my $update_rule_sql = $kbs->update_for_class($class);Returns a PostgreSQL rule that manages UPDATE statements executed against the view for the class. The rule ensures that the UPDATE statement updates the table for the class as well as any parent classes. Extended and mediated objects are also updated, but other contained objects are ignored, and should be updated separately.delete_for_class my $delete_rule_sql = $kbs->delete_for_class($class);Returns a PostgreSQL rule that manages DELETE statements executed against the view for the class. Deletes simply pass through to the underlying table for the class; parent object records are left in tact.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.setup_code my $setup_sql = $kbs->setup_code;Returns any SQL statements that must be executed after the creation of a database, but before any database objects are created. This implementation returns statement to perform the following tasks:Creates a domain, "state", that can be used as a column type in Object::Relation tables. Requirements: · Perl


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