Smolder::DB
Database connections and Object-Relational-Mapper methods
In your subclass,
use base 'Smolder::DB';
and now you have Class::DBI::mysql methods ready for use.
my $obj = Smolder::DB::Class->new;
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.
Get the database handle.
Commit the current transaction
Rollback to the last commit
commit
Disconnects the current database handle stored in db_Main.
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.
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');
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':
$column
my $values = Smolder::DB::Foo->column_values($column, 's');
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.
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.
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.
Returns the full path to the SQLite DB file.
Given the runs the SQL contained in the file against out SQLite DB
Smolder::DB->run_sql_file('/usr/local/smolder/foo.sql');
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');
This method will create a brand new, completely empty database file for Smolder.
Smolder::DB->create_database();
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($@); }
Given a DateTime object, return the string we want to store in the database
Given a date string, return the DateTime object it represents.
To install Smolder, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Smolder
CPAN shell
perl -MCPAN -e shell install Smolder
For more information on module installation, please visit the detailed CPAN module installation guide.