-
-
Save nothingmuch/460539 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Scalar::Util qw(refaddr); | |
use Test::More;use Test::Exception; | |
use KiokuDB; | |
BEGIN { | |
plan skip_all => "DBD::SQLite are required" unless eval { require DBI; require DBD::SQLite }; | |
} | |
{ | |
package MyApp::DB::Result::Foo; | |
use base qw(DBIx::Class::Core); | |
__PACKAGE__->load_components(qw(KiokuDB)); | |
__PACKAGE__->table('foo'); | |
__PACKAGE__->add_columns(qw(id name object)); | |
__PACKAGE__->set_primary_key('id'); | |
__PACKAGE__->kiokudb_column('object'); | |
package MyApp::DB; | |
use base qw(DBIx::Class::Schema); | |
__PACKAGE__->load_components(qw(Schema::KiokuDB)); | |
__PACKAGE__->register_class( Foo => qw(MyApp::DB::Result::Foo)); | |
__PACKAGE__->define_kiokudb_schema(); | |
package Foo; | |
use Moose; | |
has name => ( isa => "Str", is => "ro" ); | |
has obj => ( isa => "Object", is => "ro", weak_ref => 1 ); | |
__PACKAGE__->meta->make_immutable; | |
} | |
my $schema = MyApp::DB->connect('dbi:SQLite:dbname=:memory:'); | |
my $dir = $schema->kiokudb_handle; | |
$dir->backend->create_tables; | |
#my $dir = KiokuDB->connect("dbi:SQLite:dbname=:memory:", schema => "MyApp::DB", create => 1 ); | |
#my $schema = $dir->backend->schema; | |
$dir->txn_do( scope => 1, body => sub { | |
$dir->insert( foo => my $obj = Foo->new ); | |
$schema->resultset("Foo")->create({ id => 1, name => "foo", object => $obj }); | |
my $row = $dir->backend->schema->resultset("Foo")->create({ id => 2, name => "foo", object => "foo" }); | |
isa_ok( $row->object, 'Foo', 'inflated from constructor' ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment