Michael Peters > Smolder-1.51 > Smolder::DB

Download:
Smolder-1.51.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  7
Open  15
View/Report Bugs
Source   Latest Release: Smolder-1.52

NAME ^

Smolder::DB

Database connections and Object-Relational-Mapper methods

SYNOPSIS ^

In your subclass,

 use base 'Smolder::DB';

and now you have Class::DBI::mysql methods ready for use.

 my $obj = Smolder::DB::Class->new;

DESCRIPTION ^

This class provides a single place for handling all of the database connections in Smolder. It is a subclass of Class::DBI::mysql and provides a base class for object persistence using Class::DBI.

It also provides a connect() method for getting a DBI connection from non Class::DBI code.

INTERFACE ^

dbh

Get the database handle.

commit

Commit the current transaction

rollback

Rollback to the last commit

disconnect

Disconnects the current database handle stored in db_Main.

vars

Object method that returns a hash where the keys are the names of the columns and the values are the current values of those columns.

enum_values

Returns an arrayref containing the different values that an emum column can hold. If used as a method on a subclass then it will use that class to determine which table to use. Else, if called on the Smolder::DB base class, it will accept 2 arguments, the first being the table to use.

    my $values = Smolder::DB::Foo->enum_values('some_column');

    my $values  = Smolder::DB->enum_values('table', 'some_column');

column_values

Returns an array ref of all the unique values in a table's column This must be used in a sub class (it's an abstract method).

    my $values = Smolder::DB::Foo->column_values($column);

May also be passed a second optional argument which will be used to limit the values returned to those that start with the given string.

For example, to retrieve all of the values for a given $column that begin with the letter 's':

    my $values = Smolder::DB::Foo->column_values($column, 's');

refresh

TODO CURRENT DOES NOT WORK!!!!

This object method will through away the object in memory and re-fetch it from the database. This is useful when changes could be made in the db in another thread (such as testing) and you want to make sure the object is current.

retrieve_all_sorted_by($column_name)

This object methed is exported from Class::DBI::Plugin::RetrieveAll. It takes a name of the data field that you wish to sort by. Otherwise it works like a normal Class::DBI retrieve_all. Please see Class::DBI::Plugin::RetrieveAll or more details.

retrieve_all_sort_field($column_name)

This object method changes the default retrieve_all() in the Class to be auto-sorted by the specified column. Please see Class::DBI::Plugin::RetrieveAll for more details.

db_file

Returns the full path to the SQLite DB file.

run_sql_file

Given the runs the SQL contained in the file against out SQLite DB

    Smolder::DB->run_sql_file('/usr/local/smolder/foo.sql');

dump_database

Given the filename of where to put the dump, this method will create the SQL necessary to restore the database to it's present state including all schema creationg statements.

    Smolder::DB->dump_database('/usr/local/smolder/dump.sql');

create_database

This method will create a brand new, completely empty database file for Smolder.

    Smolder::DB->create_database();

unique_failure_msg

Given a DB failure message, will return true if the message was a failure due to a failed UNIQUE contstraint, else will return false.

    eval { $class->create(%args) };
    if( $@ ) {
        die unless Smolder::DB->unique_failure_msg($@);
    }

format_datetime

Given a DateTime object, return the string we want to store in the database

parse_datetime

Given a date string, return the DateTime object it represents.

SEE ALSO ^

DBI
Class::DBI
Class::DBI::SQLite
Class::DBI::Plugin::RetrieveAll
syntax highlighting: