switch to hashref based for command args and results
[dbsrgits/DBIx-Data-Store-old.git] / t / 01basic_collection.t
CommitLineData
65b76960 1use strict;
2use warnings FATAL => 'all';
3use Test::More;
4use DBIx::Data::Store;
5use DBIx::Data::Store::CRUD;
6use DBIx::Data::Collection::Set;
7
8use DBI;
9
10my $dsn = 'dbi:SQLite:tmp.db';
11
12my @expect;
13
14{
15 unlink('tmp.db');
16 my $dbh = DBI->connect($dsn);
17 $dbh->do(q{
18 CREATE TABLE person (
19 id INTEGER NOT NULL PRIMARY KEY,
20 name VARCHAR(255) NOT NULL
21 )
22 });
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 };
27}
28
29sub make_set {
30 DBIx::Data::Collection::Set->new(
31 store => DBIx::Data::Store::CRUD->new(
32 raw_store => DBIx::Data::Store->connect($dsn),
33 select_sql => q{SELECT id, name FROM person},
3347c67e 34 select_column_order => [ qw(id name) ],
65b76960 35 ),
65b76960 36 );
37}
38
39my $set = make_set;
40
41is_deeply([ $set->flatten ], \@expect, 'Basic data out ok (flatten)');
42
43{
44 my $stream = $set->as_stream;
45
46 my @got; while (my ($next) = $stream->next) { push @got, $next }
47
48 is_deeply(\@got, \@expect, 'Basic data out ok (stream)');
49}
50
51done_testing;