DB::Introspector
use DB::Introspector; my $introspector = DB::Introspector->get_instance($dbh); my $table = $introspector->find_table('foo'); print $table->name; # showing the table's indexes foreach my $index ($table->indexes) { print $index->name.": (".join(",",$index->column_names).")\n"; } # showing the table's foreign keys foreach my $foreign_key ($table->foreign_keys) { print $foreign_key->foreign_table->name; print join(",",$foreign_key->foreign_column_names); } # showing foreign keys that reference this table ('foo') foreach my $foreign_key ($table->dependencies) { print "Some other table :".$foreign_key->local_table->name ." is pointing to me\n"; } my @tables = $introspector->find_all_tables; # you can do other cool stuff; just read the docs.
DB::Introspector looks into database metadata and derives detailed table level and foreign key information in a way that conforms to a collection common interfaces across all dbs. The DB::Introspector::Utils::* classes take advantage of these common interfaces in order to carry out relationship traversal algorithms (like finding the column level and table level mappings between two indirectly related tables).
Params:
$table_name - the name of the table that you wish to find
Returns: DB::Introspector::Base::Table
Returns: An array (@) of DB::Introspector::Base::Table instances for each table that exists in the database.
$dbh - An instance of a DBI database handle.
Returns: DB::Introspector instance
Returns: A DBI database handle instance (DBI::db).
DB::Introspector::Base::Table
DB::Introspector::Base::ForeignKey
DB::Introspector::Utils::RelInspect
DB::Introspector::Base::BooleanColumn
DB::Introspector::Base::CharColumn
DB::Introspector::Base::Column
DB::Introspector::Base::DateTimeColumn
DB::Introspector::Base::IntegerColumn
DB::Introspector::Base::StringColumn
DBI
Masahji C. Stewart
The DB::Introspector module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install DB::Introspector, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DB::Introspector
CPAN shell
perl -MCPAN -e shell install DB::Introspector
For more information on module installation, please visit the detailed CPAN module installation guide.