NAME

oEdtk::SchemaScan - driver-neutral database schema introspection

SYNOPSIS

use oEdtk::SchemaScan qw(scan_schema);

my $schema = scan_schema($dbh);
# { driver => 'Pg', tables => { 'T' => { columns => [...], indexes => [...] } } }

DESCRIPTION

Introspects a live database handle and returns a plain data structure: for each table, the ordered columns (name, declared type and size, nullability, default, position, key rank) and the secondary indexes. It supports PostgreSQL, MySQL/MariaDB and SQLite. It loads no oEdtk code on purpose, so a snapshot tool can use it without the load banner. It is shared by tools/schema_snapshot.pl and oEdtk::DBAdmin's schema detection.

FUNCTIONS

scan_schema

my $schema = scan_schema($dbh);

Introspect $dbh and return a hash reference with the driver and tables keys. An unsupported driver is an error.

driver_of

my $driver = driver_of($dsn);

Return the tool's driver name (Pg, mysql or SQLite) for a DSN, or undef when the DSN is not supported.

size_from_type

my $size = size_from_type($type);

Return the declared length of a type such as VARCHAR2(36), or undef when the type carries no length.

The per-driver scanners _scan_pg, _scan_mysql and _scan_sqlite, and the _driver_of_dbh helper, are internal and are not part of the public API.

AUTHOR

The oEdtk team.