On Sun, Jan 24, 2010 at 10:55:35PM -0500, Hinrik Orn Sigurdsson via RT wrote:
Show quoted text> Sun Jan 24 22:55:34 2010: Request 53969 was acted upon.
> Transaction: Ticket created by HINRIK
> Queue: DBIx-Perlish
> Subject: Runtime column names
> Broken in: (no value)
> Severity: Wishlist
> Owner: Nobody
> Requestors: hinrik.sig@gmail.com
> Status: new
> Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=53969 >
>
>
> It would be very useful to be able to compute column names at runtime.
> This is possible with table names via C<< my $t : table = $name; >>, but
> in the case of columns it can only be done inside a string used in a
> return statement (e.g. C<< return "$t->{$col};" >>). It would be nice if
> C<< table->{$col} == $value; >> and such were possible.
>
> The docs mention that this might be added in a future version. So,
> consider this an official request. :)
I don't understand. Consider this script:
===
#! /usr/bin/perl
use 5.006;
use strict;
use warnings;
use DBIx::Perlish;
use DBD::SQLite;
use Data::Dump;
my $dbh = DBI->connect("dbi:SQLite:");
$dbh->do("create table names (id integer, name text)");
db_insert 'names', { id => 1, name => "hello" };
db_insert 'names', { id => 33, name => "smth/xx" };
db_insert 'names', { id => 3, name => "ehlo" };
fetch(id => 3);
fetch(name => "hello");
sub fetch {
my ($col, $val) = @_;
my $r = db_fetch {
names->$col == $val;
};
dd $r;
}
===
It produces
{ id => 3, name => "ehlo" }
{ id => 1, name => "hello" }
Is that what you want?
--
Matters of elegance ought to be left to the tailor and to the cobbler.
-- L. Boltzmann