The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::DBBrowser::DB - Database plugin documentation.

VERSION

Version 2.287

DESCRIPTION

A database plugin provides the database specific methods. App::DBBrowser considers a module whose name matches /^App::DBBrowser::DB::[^:']+\z/ and which is located in one of the @INC directories as a database plugin.

The user can add an installed database plugin to the available plugins in the options menu (db-browser -h) by selecting DB Options and then DB Plugins.

A suitable database plugin provides the methods named in this documentation.

METHODS

Required methods

new( $info, $opt )

The constructor method.

When db-browser calls the plugin constructor it passes tow arguments:

    sub new {
        my ( $class, $info, $opt ) = @_;
        my $self = {
            info => $info,
            opt  => $opt
        };
        return bless $self, $class;
    }

    # $info->{app_dir}        -> path to the configuration directoriy of the app
    # $info->{sqlite_search}  -> true if C<db-browser> was called with the argument C<-s|--search>
    # $opt->{G}{metadata}     -> Options/Sql/Metadata

Returns the created object.

get_db_driver()

Returns the name of the DBI database driver used by the plugin.

get_databases();

Returns two array references: the first reference refers to the array of user-databases the second refers to the array of system-databases. The second array reference is optional.

If the option metadata is true, user-databases and system-databases are used else only the user-databases are used.

get_db_handle( $database )

Returns the database handle.

db-browser expects a DBI database handle with the attribute RaiseError enabled.

Optional methods

get_schemas( $dbh, $database )

$dbh is the database handle returned by the method db_hanlde.

Returns the user-schemas as an array-reference and the system-schemas as an array-reference (if any).

If the option metadata is true, user-schemas and system-schemas are used else only the user-schemas are used.

EXAMPLE

    package App::DBBrowser::DB::MyPlugin;
    use strict;
    use DBI;

    sub new {
        my ( $class ) = @_;
        return bless {}, $class;
    }

    sub get_db_driver {
        my ( $self ) = @_;
        return 'Pg';
    }

    sub get_db_handle {
        my ( $self, $db ) = @_;
        my $dbh = DBI->connect( "DBI:Pg:dbname=$db", 'user', 'password', {
            RaiseError => 1,
            PrintError => 0,
        }) or die $DBI::errstr;
        return $dbh;
    }

    sub get_databases {
        my ( $self ) = @_;
        return [ 'My_DB_1', 'My_DB_2' ];
    }

    1;

AUTHOR

Matthäus Kiem <cuer2s@gmail.com>

LICENSE AND COPYRIGHT

Copyright 2012-2021 Matthäus Kiem.

THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For details, see the full text of the licenses in the file LICENSE.