NAME

DbFramework::DataModel - Data Model class

SYNOPSIS

use DbFramework::DataModel;
$dm = new DbFramework::DataModel($name,$db,$host,$port,$user,$pass);
$dm->init_db_metadata;
@tables = @{$dm->collects_table_l};
%tables = %{$dm->collects_table_h};
@tables = @{$dm->collects_table_h_byname(@tables)};
$sql    = $dm->as_sql;

DESCRIPTION

A DbFramework::DataModel object represents a Mysql database schema. It can be initialised using metadata from a Mysql database which is structured according to a few simple rules.

SUPERCLASSES

DbFramework::Util

DATA MODEL RULES

Foreign Keys

For init_db_metadata() to handle foreign keys correctly, each foreign key name must be of the form f_$table where $table is the name of the table with the related primary key.

CLASS METHODS

new($name,$db,$host,$port,$user,$password)

Create a new DbFramework::DataModel object called $name. $db is the name of a Mysql database associated with the data model. $host, $port, $user, $password are optional arguments specifying the host, port, username and password to use when connecting to the database.

OBJECT METHODS

A data model has a number of tables. These tables can be accessed using the attributes COLLECTS_TABLE_L and COLLECTS_TABLE_H. See "AUTOLOAD()" in DbFramework::Util for the accessor methods for these attributes.

name($name)

If $name is supplied, sets the data model name. Returns the data model name.

as_sql()

Returns a SQL string which can be used to create the tables which make up the data model.

init_db_metadata()

Returns a DbFramework::DataModel object configured using metadata from the Mysql database handle returned by dbh(). Foreign keys will be automatically configured for tables in the data model (but see "DATA MODEL RULES" for information on foreign key names.) This method will die() unless the number of attributes and the attribute names in each foreign and related primary keys match.

SEE ALSO

DbFramework::Table and DbFramework::Util.

AUTHOR

Paul Sharpe <paul@miraclefish.com>

COPYRIGHT

Copyright (c) 1997,1998 Paul Sharpe. England. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

ACKNOWLEDGEMENTS

Once upon a time, on a CPAN mirror not so far away there was Msql::RDBMS.