Skip Menu |
 

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 25446
Status: resolved
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] CDBICompat wrapper for Class::DBI::AbstractSearch
Download (untitled) / with headers
text/plain 424b
CDBI::AbstractSearch is a commonly used plug in for CDBI which provides a search_where function that is pretty much a subset of DBIx::Class::ResultSet->search. The attached patch provides a very thin CDBICompat layer for it. The tests assume that 25445 has been fixed. This isn't really required, I don't even know if the real AbstractSearch can do an offset without a limit, so feel free to remove the only offset test.
Subject: abstract_search.patch
---------------------------------------------------------------------- r27701: schwern | 2007-03-14 19:27:30 -0700 AbstractSearch compatibility layer. ---------------------------------------------------------------------- === local/DBIx-Class/t/cdbi-abstract (new directory) ================================================================== === local/DBIx-Class/t/cdbi-abstract/search_where.t ================================================================== --- local/DBIx-Class/t/cdbi-abstract/search_where.t (revision 27700) +++ local/DBIx-Class/t/cdbi-abstract/search_where.t (revision 27701) @@ -0,0 +1,61 @@ +#!/usr/bin/perl -w + +use Test::More; + +use strict; +use warnings; + +BEGIN { + eval "use DBIx::Class::CDBICompat;"; + if ($@) { + plan (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@"); + next; + } + eval "use DBD::SQLite"; + plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 8); +} + +INIT { + use lib 't/testlib'; + use Film; +} + + +Film->create({ Title => $_ }) for ("Superman", "Batman", "Super Fuzz"); + +my $superman = Film->search_where( Title => "Superman" ); +is $superman->next->Title, "Superman", "search_where() as iterator"; +is $superman->next, undef; + +my @all = Film->search_where({}, { order_by => "Title ASC" }); +is_deeply ["Batman", "Super Fuzz", "Superman"], + [map $_->Title, @all], + "order_by ASC"; + +@all = Film->search_where({}, { order_by => "Title DESC" }); +is_deeply ["Superman", "Super Fuzz", "Batman"], + [map $_->Title, @all], + "order_by DESC"; + +@all = Film->search_where({}, { limit => 2, order_by => "Title ASC" }); +is_deeply ["Batman", "Super Fuzz"], + [map $_->Title, @all], + "limit"; + +@all = Film->search_where({}, { offset => 1, order_by => "Title ASC" }); +is_deeply ["Super Fuzz", "Superman"], + [map $_->Title, @all], + "offset"; + +@all = Film->search_where({}, { limit => 1, offset => 1, order_by => "Title ASC" }); +is_deeply ["Super Fuzz"], + [map $_->Title, @all], + "limit + offset"; + +@all = Film->search_where({}, { limit => 2, offset => 1, + limit_dialect => "Top", order_by => "Title ASC" + }); +is_deeply ["Super Fuzz", "Superman"], + [map $_->Title, @all], + "limit_dialect ignored"; + === local/DBIx-Class/lib/DBIx/Class/CDBICompat.pm ================================================================== --- local/DBIx-Class/lib/DBIx/Class/CDBICompat.pm (revision 27700) +++ local/DBIx-Class/lib/DBIx/Class/CDBICompat.pm (revision 27701) @@ -32,6 +32,7 @@ Retrieve Pager ColumnGroups + AbstractSearch ImaDBI/); #DBIx::Class::ObjIndexStubs @@ -74,6 +75,10 @@ =item AccessorMapping +=item AbstractSearch + +Compatibility with Class::DBI::AbstractSearch. + =item AttributeAPI =item AutoUpdate
I forgot to include the AbstractSearch compat module in the patch. Here it is.
---------------------------------------------------------------------- r27710: schwern | 2007-03-16 20:07:33 -0700 Forgot to check this in. ---------------------------------------------------------------------- === local/DBIx-Class/lib/DBIx/Class/CDBICompat/AbstractSearch.pm ================================================================== --- local/DBIx-Class/lib/DBIx/Class/CDBICompat/AbstractSearch.pm (revision 27709) +++ local/DBIx-Class/lib/DBIx/Class/CDBICompat/AbstractSearch.pm (revision 27710) @@ -0,0 +1,23 @@ +package # hide form PAUSE + DBIx::Class::CDBICompat::AbstractSearch; + +use strict; +use warnings; + +# The keys are mostly the same. +my %cdbi2dbix = ( + limit => 'rows', +); + +sub search_where { + my $class = shift; + my $where = (ref $_[0]) ? $_[0] : { @_ }; + my $attr = (ref $_[0]) ? $_[1] : {}; + + # Translate the keys + $attr->{$cdbi2dbix{$_}} = delete $attr->{$_} for keys %cdbi2dbix; + + return $class->resultset_instance->search($where, $attr); +} + +1;
"resolved", at least once your patch set hits


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.