3 use DBIx::Data::Store::CRUD;
4 use DBIx::Data::Collection::Set;
8 use warnings FATAL => 'all';
10 my $dsn = 'dbi:SQLite:tmp.db';
15 sort { $a->{name} cmp $b->{name} } @_
20 my $dbh = DBI->connect($dsn);
23 id INTEGER NOT NULL PRIMARY KEY,
24 name VARCHAR(255) NOT NULL
27 my $pop = $dbh->prepare(q{INSERT INTO person (name) VALUES (?)});
28 my @names = qw(Joe Jim Bob Pterry);
29 $pop->execute($_) for @names;
30 @expect = sort_set do {
31 my $id = 0; map +{ id => ++$id, name => $_ }, @names
36 my ($set, $crud) = @_;
37 DBIx::Data::Collection::Set->new(
38 store => DBIx::Data::Store::CRUD->new(
39 raw_store => DBIx::Data::Store->connect($dsn),
40 select_sql => q{SELECT id, name FROM person},
41 select_column_order => [ qw(id name) ],
50 is_deeply([ sort_set $set->flatten ], \@expect, 'Basic data out ok (flatten)');
53 my $stream = $set->as_stream;
55 my @got; while (my ($next) = $stream->next) { push @got, $next }
57 is_deeply([ sort_set @got ], \@expect, 'Basic data out ok (stream)');
60 $set = make_set { class => 'Spoon' };
63 [ sort_set $set->flatten ],
64 [ map { bless({ %$_ }, 'Spoon') } @expect ],
65 'Basic data with class out ok'