NAME
XAS::Model::Database - A class to load database schemas
SYNOPSIS
use XAS::Model::Database
schema => 'ETL::Model::Database',
table => 'Master';
try {
$schema = XAS::Model::Database->opendb('database');
my @rows = Master->search($schema);
foreach my $row (@rows) {
printf("Hostname = %s\n", $row->Hostname);
}
} catch {
my $ex = $_;
print $ex;
};
DESCRIPTION
This module loads DBIx::Class table definations and defines a path for the database.ini configuration file. It can also load shortcut constants for table definations.
Example
use XAS::Model::Database
schema => 'ETL::Model::Database',
table => 'Master'
;
or
use XAS::Model::Database
schema => 'ETL::Model::Database',
tables => qw( Master Detail )
;
or
use XAS::Model::Database
schema => 'ETL::Model::Database',
table => ':all'
;
The difference is that in the first example you are only loading the "Master" constant into your module. The second example loads the constants "Master" and "Detail". The ":all" qualifer would load all the defined constants.
HOOKS
The following hooks are defined to load table definations and define constants. The order that they are called is important, i.e. 'schema' must come before 'table'.
schema
This defines a load path to the modules that defines a database schema. DBIx::Class loads modules based on the path. For example all modules below 'ETL::Model::Database' will be loaded at once. You can be more specific. If you only want the 'Progress' database schema you can load it by using 'ETL::Model::Database::Progress'.
table
This will define a constant for a table defination. This constant is based on the table name, which is defined by the modules name. So the module 'ETL::Model::Database::Progress::ActOther' will have a constant named 'ActOther' that refers to the module.
- Warning
-
If you have multiple tables named the same thing in differant schemas and load all the schemas at once, this constant will refer to the last loaded table defination.
tables
Does the same thing as 'table'.
METHODS
opendb($database)
This method provides the defaults necessary to call the DBIx::Class::Schema connect() method. It takes one parameter.
- $database
-
The name of a configuration item suitable for DBIx::Class::Schema::Configure.
Example
my $handle = XAS::Model::Database->opendb('database');
SEE ALSO
- DBIx::Class
- XAS
AUTHOR
Kevin Esteb, <kevin@kesteb.us>
COPYRIGHT AND LICENSE
Copyright (C) 2013 by Kevin L. Esteb
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.