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

NAME

DBIx::DBObj

DESCRIPTION

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.

CLASS VARIABLES

DBObjTable

Required, defines the table this DBObj maps to.

DBObjPKeys

Required, defines the primary keys for the table this DBObj maps to.

DBObjFields

Required, defines the fields available to this DBObj.

DBObjThrow

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.

METHODS

create

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.

find

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.

delete

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.

update

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.