DbFramework::DataModel - Data Model class


NAME

DbFramework::DataModel - Data Model class


SYNOPSIS

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


DESCRIPTION

A DbFramework::DataModel object represents a database schema. It can be initialised using the metadata provided by a DBI driver and a catalog database (see the DbFramework::Catalog manpage).


SUPERCLASSES

DbFramework::Util


CLASS METHODS

new($name,$dsn,$user,$password)

Create a new DbFramework::DataModel object. $name is the name of the database associated with the data model. $dsn is the DBI data source name associated with the data model. $user and $password are optional arguments specifying the 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 methods COLLECTS_TABLE_L and COLLECTS_TABLE_H. See AUTOLOAD() in the DbFramework::Util manpage for the accessor methods for these attributes.

name($name)

If $name is supplied sets the name of the database associated with the data model. Returns the database name.

dsn()

Returns the DBI DSN of the database associated with the data model.

db()

Synonym for name().

driver()

Returns the name of the driver associated with the data model.

as_sql()

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

init_db_metadata($catalog_dsn,$user,$password)

Returns a DbFramework::DataModel object configured using metadata from the database handle returned by dbh() and the catalog (see the DbFramework::Catalog manpage). $catalog_dsn is the DBI data source name associated with the catalog. $user and $password are used for authorisation against the catalog database. Foreign keys will be automatically configured for tables in the data model but this method will die() unless the number of attributes in each foreign and related primary key match.


SEE ALSO

the DbFramework::Catalog manpage, the DbFramework::Table manpage and the DbFramework::Util manpage.


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

This module was inspired by Msql::RDBMS.

 DbFramework::DataModel - Data Model class