Class-DBI-ViewLoader

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

        @classes = $obj->load_views

    The main method for the class, loads all relevant views from the
    database and generates classes for those views.

    The generated classes will be read-only and have a multi-column primary
    key containing every column. This is because it is not guaranteed that
    the view will have a real primary key and Class::DBI insists that there
    should be a unique identifier for every row.

    If the newly generated class inherits a "Main" Class::DBI handle (via
    "connection" or "set_db" calls in base classes) that handle will be used
    by the class. Otherwise, a new connection is set up for the classes
    based on the loader's connection.

    Usually, any row containing an undef (NULL) primary key column is
    considered false in boolean context, in this particular case however
    that doesn't make much sense. So only all-null rows are considered false
    in classes generated by this class.

    Each class is only ever generated once, no matter how many times
    load_views() is called. If you want to load the same view twice for some
    reason, you can achieve this by changing the namespace.

    Returns class names for all created classes.

  view_to_class
        $class = $obj->view_to_class($view)

    Returns the class for the given view name. This depends on the object's
    current namespace, see set_namespace(). It doesn't matter if the class
    has been loaded, or if the view exists in the database.

    If this method is called without arguments, or with an empty string, it
    returns an empty string.

  _get_dbi_handle
        $dbh = $obj->_get_dbi_handle

    Returns a DBI handle based on the object's dsn, username and password.
    This generally shouldn't be called externally (hence the leading
    underscore).

    Making multiple calls to this method won't cause multiple connections to
    be made. A single handle is cached by the object from the first call to
    _get_dbi_handle until such time as the object goes out of scope or
    set_dsn is called again, at which time the handle is disconnected and
    the cache is cleared.

    If the connection fails, a fatal error is raised.

  _clear_dbi_handle
        $obj->_clear_dbi_handle

    This is the cleanup method for the object's DBI handle. It is called
    whenever the DBI handle needs to be closed down. i.e. when a new handle
    is used or the object goes out of scope. Subclasses should override this
    method if they need to clean up any state data that relies on the
    current database connection, like statement handles for example. If you
    don't want the handle that the object is using to be disconnected, use
    the _set_keepalive method.

        sub _clear_dbi_handle {
            my $self = shift;

            delete $self->{statement_handle};

            $self->SUPER::_clear_dbi_handle(@_);
        }

  _set_dbi_handle
        $obj = $obj->_set_dbi_handle($dbh)

    This method is used to attach a DBI handle to the object. It might prove
    useful to use this method in order to use an existing database
    connection in the loader object. Note that unlike set_dsn, calling this
    method directly will not cause an appropriate driver to be loaded. See
    _load_driver for that.

  _set_keepalive
        $obj = $obj->_set_keepalive($bool)

    When set to true, the database handle used by the object won't be
    disconnected automatically.

  _load_driver
        $obj = $obj->_load_driver($driver_name)

    This method is used internally by set_dsn to load a driver to handle
    database-specific functionality. It can be called directly in
    conjunction with _set_dbi_handle to load views from an existing database
    connection.

DRIVER METHODS
    The following methods are provided by the relevant driver classes. If
    they are called on a native Class::DBI::ViewLoader object (one without a
    dsn set), they will cause fatal errors. They are documented here for the
    benefit of driver writers but they may prove useful for users also.

    *   base_class

            $class = $driver->base_class

        Should return the name of the base class to be used by generated
        classes. This will generally be a Class::DBI driver class.

            package Class::DBI::ViewLoader::Pg;

            # Generate postgres classes
            sub base_class { "Class::DBI::Pg" }

    *   get_views

            @views = $driver->get_views;

        Should return the names of all the views in the current database.

    *   get_view_cols

            @columns = $driver->get_view_cols($view);

        Should return the names of all the columns in the given view.

    A list of these methods is provided by this class, in
    @Class::DBI::ViewLoader::driver_methods, so that each driver can be sure
    that it is implementing all required methods. The provided
    t/04..plugin.t is a self-contained test script that checks a driver for
    compatibility with the current version of Class::DBI::ViewLoader, driver
    writers should be able to copy the test into their distribution and edit
    the driver name to provide basic compliance tests.

DIAGNOSTICS
    The following fatal errors are raised by this class:

    *   No dsn

        set_dsn was called without an argument

    *   Invalid dsn %s

        the dsn passed to set_dsn couldn't be parsed by DBI->parse_dsn



( run in 1.033 second using v1.01-cache-2.11-cpan-39bf76dae61 )