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(
39 store => DBIx::Data::Store::CRUD->new(
40 raw_store => DBIx::Data::Store->connect($dsn),
41 select_sql => q{SELECT id, name FROM person},
42 select_column_order => [ qw(id name) ],
51 is_deeply([ sort_set $set->flatten ], \@expect, 'Basic data out ok (flatten)');
54 my $stream = $set->as_stream;
56 my @got; while (my ($next) = $stream->next) { push @got, $next }
58 is_deeply([ sort_set @got ], \@expect, 'Basic data out ok (stream)');
61 $set = make_set { class => 'Spoon' };
64 [ sort_set $set->flatten ],
65 [ map { bless({ %$_ }, 'Spoon') } @expect ],
66 'Basic data with class out ok'
70 insert_sql => q{INSERT INTO person (name) VALUES (?) },
71 insert_argument_order => [ 'name' ],
72 insert_command_constructor => sub {
73 require DBIx::Data::Store::Command::Insert::LastInsertId;
75 DBIx::Data::Store::Command::Insert::LastInsertId->new(
77 raw_store => $self->raw_store,
78 insert_call_command => $self->raw_store->new_call_command(@_)
83 my $doug = $set->add({ name => 'Doug' });