Hi,
I need help for my module name, hoping for someone's creative insight. Also
would enjoy any comments. This is a DBIC::Schema component and stand alone
class this is like a $schema->populate on steroids. What it does is make it
easier when you are doing a first time setup and need to insert a bunch of
rows, like the first time you deploy a new database, or after you update it.
It's not as full featured as DBIC::Fixtures, and is targeted more directly at
making it easier to just take a perl structure, or one loaded from a
configuration file, and setup your database.
Basically all it does is take:
my $setup_rows = [
{Gender => {
fields => 'label',
data => {
male => 'male',
female => 'female',
}}},
{Person => {
fields => ['name', 'age', 'gender', 'emails'],
data => {
john => ['john', 38, "!Index:Gender.male", {
fields => ['email', 'private'],
data => {
personal => ['[EMAIL PROTECTED]', 1],
work => ['[EMAIL PROTECTED]', 0],
},
}],
jane => ['jane', 40, '!Index:Gender.female'],
}}},
{FriendList => {
fields => ['person', 'friend'],
data => {
john_jane => ['!Index:Person.john', '!Index:Person.jane'],
}}},
];
and let's you put rows into your schema with:
$schema->populate_via_hashref($setup_rows);
The main thing over the standard populate -or even insert- is that each
$setup_rows is traversed via a visitor class so it can process the values and
expand a macro-like "!Macro:args". This makes it easier to do things like
setup a database with relationships and not have to predetermine the keys, or
include defaults dates (with something like "!Date:now' or "!Date::yesterday")
or even base inserted values on %ENV. Your thoughts on additional builtin
macros wanted.
I'm actually using DBIC::Fixtures myself now, but I wrote this for some
previous jobs and thought it might come in handy for someone else. It's
probably not what you want to use if you are installing 100's of rows, need to
dump and reload your db, since DBIC::Fixtures is great for that. It's got a
decent test suite and all, just need a good name for it to live on CPAN. I
just need a name (been using DBIx::Class::PopulateViaHashRef internally) and
your comments.
Thanks!
John Napiorkowski
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]