NAME
Class::PObject::Driver::mysql - mysql driver for Class::PObject
SYNOPSIS
pobject Person => {
columns => ['id', 'name', 'email'],
driver => 'mysql',
datasource=> {
DSN => 'dbi:mysql:db_name',
UserName => 'sherzodr',
Password => 'secret',
Table => 'person',
}
};
DESCRIPTION
Class::PObject::Driver::mysql is a driver for Class::PObject for storing object data in mysql tables. Following class properties are required:
driver
- tells Class::PObject to use 'mysql' driver.datasource
- gives the DBI details on how to connect to mysql database.datasource
should be in the form of a hashref, and should definedDSN
,UserName
andPassword
. If you ommitTable
, it will default to the name of the object, lowercased, and non-alphanumeric values replaced with '_'. For example, if you define an object as:pobject Gallery::User => { columns => \@columns, driver => 'mysql', datasource=> { DSN => 'dbi:mysql:gallery', UserName => 'sherzodr', Password => 'secret', } };
It will store itself into a table 'gallery_user' inside 'gallery' database. You can use 'Table' 'datasource' attribute if you want to override this default behavior:
pobject Gallery::User => { columns => \@columns, driver => 'mysql', datasource=> { DSN => 'dbi:mysql:gallery', UserName => 'sherzodr', Password => 'secret', Table => 'user' } };
OBJECT STORAGE
Objects of the same type are stored in the same table, as seperate records. Each column of the object represents one column of the database table. It's required that you first create your tables for storing the objects.
ID GENERATION
There is no direct id generation routine available on this driver. It is directly manipulated by mysql's 'AUTO_INCREMENT' column type. It means, you should ALWAYS declare your 'id' columns as AUTO_INCREMENT PRIMARY KEY.
SERIALIZATION
There is no direct serialization applied on the data. All the data goes as is into respective columns of the table.
SEE ALSO
Class::PObject, Class::PObject::Driver::csv, Class::PObject::Driver::file
AUTHOR
Sherzod Ruzmetov <sherzodr@cpan.org>