DBIx::DBObj
DBIx::DBObj provides a lightweight OO interface to interact with records in a SQL database. DBIx::DBObj has some functional overlap with a another Perl module DBIx::SearchBuilder. The major difference between the two is that DBObj does not try to provide a OO API for costructing complex SQL queries.
Required, defines the table this DBObj maps to.
Required, defines the primary keys for the table this DBObj maps to.
Required, defines the fields available to this DBObj.
Optional, causes DBObj to throw exceptions. In the future this will not be an option. It's only here because I have some software that predates DBObj exceptions.
class/public (DBObj $obj) create (\%create_args)
throws Error::Better::OperationFailed
DESCRIPTION: Provided a hash references of field names and values, a new row will be inserted into the database. An Error::Better::OperationFailed exception will be thrown if the insert fails for any reason.
class/public (Arrayref DBObj) search (\%search_args | $where)
DESCRIPTION: Provided a hash references of field names and values search will create a SELECT query with all the key/value pairs ANDed together. If a empty hash reference is provided search will perform an unbounded SELECT. The caller may also define their own WHERE clause and pass that to search in place of the hash reference. If there are no matching records, search will simply return an empty array reference.
class/public (DBObj $obj) find ($value1, ...)
throws Error::Better::ObjectNotFound
DESCRIPTION: The arguments to find will always match the definition of @DBObjPKeys. They must be passed in the same order as the are defined. The generated SELECT query's WHERE clause will use the tables primary keys. Unlike search, an exception will be thrown if there are no matching records.
instance/public (boolean) delete (void)
DESCRIPTION: Will delete a row from the database that matching the instance of this object. Deletes are done using the fields defined as primary keys.
instance/public (boolean) update (void)
DESCRIPTION: Will serialize any changes between the DBObj and the Database. A UPDATE query is generated using DBObj defined primary keys.
At runtime DBObj creates a bunch of accessors and mutators based on the contents of @DBObjFields. Method names are prefixed with either get or set depending on their nature. What this means is if you have a field in a table this dbobj is mapped to called 'Foo_Bar' two methods will be created 'getFoo_Bar' and 'setFoo_Bar'. In the future DBObj will have an additional layer of indirection where you will be able to define what the method name should look like for a given field.
When I created PNDI is was eventually supposed to be like JNDI. It never really got there though. Ultimatly PNDI is just a OO wrapper to global hash that happens to have some minimal GC functionality. DBObj uses PNDI to store database connection information. Future versions of DBObj will include a 'DBObjSrcKey' which will allow a DBObj to connect to a database other then the default. One of the examples (example/AppReg.pm) provides a reasonably good illustration showing how to use PNDI with DBObj.
See examples/*
To install DBIx::DBObj, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::DBObj
CPAN shell
perl -MCPAN -e shell install DBIx::DBObj
For more information on module installation, please visit the detailed CPAN module installation guide.