-package Email::Archive::Storage::DBI;
+package Email::Archive::Storage::DBIC;
use Moo;
use Carp;
use Email::MIME;
use Email::Abstract;
-use Email::Archive::Schema;
+use Email::Archive::Storage::DBIC::Schema;
use autodie;
use Try::Tiny;
with q/Email::Archive::Storage/;
has schema => (
is => 'rw',
isa => sub {
- ref $_[0] eq 'Email::Archive::Schema' or die "schema must be a Email::Archive schema",
+ ref $_[0] eq 'Email::Archive::Storage::DBIC::Schema' or die "schema must be a Email::Archive::Storage::DBIC schema",
},
);
return $deployed;
}
-sub storage_connect_dbic {
+sub storage_connect {
my ($self, $dsn) = @_;
- $self->schema(Email::Archive::Schema->connect($dsn));
+ $self->schema(Email::Archive::Storage::DBIC::Schema->connect($dsn));
my $deployed = $self->_deployed;
$self->_deploy unless $deployed;
}
-package Email::Archive::Schema;
+package Email::Archive::Storage::DBIC::Schema;
use strict;
use warnings;
-package Email::Archive::Schema::Result::Messages;
+package Email::Archive::Storage::DBIC::Schema::Result::Messages;
use strict;
use warnings;
-package Email::Archive::Schema::Result::Metadata;
+package Email::Archive::Storage::DBIC::Schema::Result::Metadata;
use strict;
use warnings;
use Test::More;
use Email::Archive;
+use Email::Archive::Storage::DBIC;
my $email = Email::MIME->create(
header => [
cmp_ok($found->header('subject'), 'eq', "Message in a bottle",
"can find stored message by ID");
+my $e_dbic = Email::Archive->new(
+ storage => Email::Archive::Storage::DBIC->new,
+);
+$e_dbic->connect('dbi:SQLite:dbname=t/test_dbic.db');
+$e_dbic->store($email);
+
+$found = $e_dbic->retrieve('helloworld');
+cmp_ok($found->header('subject'), 'eq', "Message in a bottle",
+ "can find stored message by ID");
+
+
done_testing;
unlink 't/test.db';
+unlink 't/dbic_test.db';