[CDBI] Turning Class::DBI on its side
Duncan Ferguson <duncan_j_ferguson-/[email protected]> Wed, 25 Jul 2007 14:32:42 +0100
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
Bit of a strange cry for help this (not written a module before so
some of my terminology is probably off, sorry)
I want to turn the Class::DBI objects on their side; I want to store
some application configuration within a database table, i.e.
Table: prefs
+----+------------------+----------------------------+
| id | name | value |
+----+------------------+----------------------------+
| 0 | filename | /path/to/file.txt |
| 1 | item_enabled | 1 |
| 2 | task_name | something |
+----+------------------+----------------------------+
so instead of doing
my $row=DB::Prefs->search({ name => " filename}})->first;
print $row->value,$/;
$row->value("/new/path/to/file");
I can do
print DB::Prefs->filename,$/;
or
DB::Prefs->filename("/new/path/to/file");
So, how I can set up the accessors to point to a row in the database
rather than a column? There should only be one row per name (so name
could be a primary key rather than id). I can see that I probably
have to provide/create each accessor for each distinct item in the
table (or do a generic AUTOLOAD one to search for the item and get
the value) but how do I create the correct object to be returned to
the caller?
TIA
Duncs
_______________________________________________
ClassDBI mailing list
ClassDBI-Ra3b/[email protected]
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi