Subject: | [PATCH] CDBICompat wrapper for Class::DBI::AbstractSearch |
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