[Dbix-class] How about a reverse parser script/utility? (Was: Query Building Help)

Matt S Trout dbix-class at trout.me.uk
Sat Aug 12 23:52:28 CEST 2006


Hugh Lampert wrote:
> Ash Berlin wrote:
>>> On 8/10/06, *Ash Berlin* <ash at cpan.org <mailto:ash at cpan.org>> wrote:
>>>
>>>     Right then guys:
>>>
>>>     I am trying to build the following query:
>>>     [......]
>>>     Any recourse?
> 
> Perhaps this is a crazy idea but I see I'm not the only one who 
> struggles with the DBIC syntax.  As a SQL DBA/Developer I'm a lot more 
> comfortable with SQL syntax than coding queries for DBIC. Would it be 
> possible to write a utility module or script that given a valid SQL 
> query in a string would produce the corresponding DBIC method call? 
> 
> (Please don't tell me to write this myself, I'm not that big a genius!)

Yes, it would be possible. But I'd much rather provide a query syntax for DBIC 
that more closely mirrors the SQL syntax. My two current thoughts on this are 
via operator overloading -

my $this_millenium = FROM $cds_rs WHERE { $_->year >= 2000 & $_->tracks->count 
 > 10 };

or via some hybrid syntax -

my $this_millenium = $cds_rs->search( AND( 'year' GTE 2000, 'count(tracks)' GT 
10 ) );



More information about the Dbix-class mailing list