File: 01_abstract.t

package info (click to toggle)
libclass-dbi-abstractsearch-perl 0.07-4.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 96 kB
  • sloc: perl: 28; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,044 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use strict;
use Test::More;

BEGIN {
    eval "use DBD::SQLite";
    plan $@ ? (skip_all => 'needs DND::SQLite for testing')
	: (tests => 2);
}

use DBI;

my $DB  = "t/testdb";
unlink $DB if -e $DB;

my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1 });
DBI->connect(@DSN)->do(<<SQL);
CREATE TABLE film (id INTEGER NOT NULL PRIMARY KEY, title VARCHAR(32))
SQL
    ;

package Film;

use base qw(Class::DBI);
__PACKAGE__->set_db(Main => @DSN);
__PACKAGE__->table('film');
__PACKAGE__->columns(Primary => qw(id));
__PACKAGE__->columns(All => qw(title));

use Class::DBI::AbstractSearch;

package main;
for my $i (1..50) {
    Film->create({
	title => "title $i",
    });
}

{
    my @films = Film->search_where(title => [ "title 10", "title 20" ]);
    is @films, 2, "films return 2";

    @films = Film->search_where(
      { title => { 'like' => 'title%' } },
      { limit_dialect => 'LimitOffset',
        limit         => 5,
        offset        => 10 }
    );
    is @films, 5, "films return 5";
}

END { unlink $DB if -e $DB }