3 use DBIx::Data::Store::CRUD;
4 use DBIx::Data::Collection::Set;
8 use warnings FATAL => 'all';
10 my $dsn = 'dbi:SQLite:tmp.db';
16 my $dbh = DBI->connect($dsn);
19 id INTEGER NOT NULL PRIMARY KEY,
20 name VARCHAR(255) NOT NULL
23 my $pop = $dbh->prepare(q{INSERT INTO person (name) VALUES (?)});
24 my @names = qw(Joe Jim Bob Pterry);
25 $pop->execute($_) for @names;
26 @expect = do { my $id = 0; map +{ id => ++$id, name => $_ }, @names };
30 my ($set, $crud) = @_;
31 DBIx::Data::Collection::Set->new(
32 store => DBIx::Data::Store::CRUD->new(
33 raw_store => DBIx::Data::Store->connect($dsn),
34 select_sql => q{SELECT id, name FROM person},
35 select_column_order => [ qw(id name) ],
44 is_deeply([ $set->flatten ], \@expect, 'Basic data out ok (flatten)');
47 my $stream = $set->as_stream;
49 my @got; while (my ($next) = $stream->next) { push @got, $next }
51 is_deeply(\@got, \@expect, 'Basic data out ok (stream)');
54 $set = make_set { class => 'Spoon' };
58 [ map { bless({ %$_ }, 'Spoon') } @expect ],
59 'Basic data with class out ok'