1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
use strict;
use warnings;
use Devel::Dwarn;
use With::Roles;
{
package MySchema;
use Object::Tap;
use base qw(DBIx::Class::Schema);
use DBIx::Class::ResultSource::Table;
__PACKAGE__->register_source(
Foo => DBIx::Class::ResultSource::Table->new({ name => 'foo' })
->$_tap(add_columns => qw(x y z))
);
__PACKAGE__->register_source(
Bar => DBIx::Class::ResultSource::Table->new({ name => 'bar' })
->$_tap(add_columns => qw(x y1 y2 z))
);
}
{
package MyScratchpad;
use DBIx::Class::SQLMaker::Role::SQLA2Passthrough qw(on);
MySchema->source('Foo')->add_relationship(bars => 'Bar' => on {
+{ 'foreign.x' => 'self.x',
'foreign.y1' => { '<=', 'self.y' },
'foreign.y2' => { '>=', 'self.y' },
};
});
}
my $s = MySchema->connect('dbi:SQLite:dbname=:memory:');
::Dwarn([ $s->source('Foo')->columns ]);
my $rs = $s->resultset('Foo')->search({ z => 1 });
::Dwarn(${$rs->as_query}->[0]);
$s->storage->ensure_connected;
$s->storage
->sql_maker
->with::roles('DBIx::Class::SQLMaker::Role::SQLA2Passthrough')
->plugin('+ExtraClauses')
->plugin('+BangOverrides');
warn ref($s->storage->sql_maker);
my $rs2 = $s->resultset('Foo')->search({
-op => [ '=', { -ident => 'outer.x' }, { -ident => 'me.y' } ]
}, {
'select' => [ 'me.x', { -ident => 'me.z' } ],
'!with' => [ outer => $rs->get_column('x')->as_query ],
});
::Dwarn(${$rs2->as_query}->[0]);
my $rs3 = $s->resultset('Foo')
->search({}, { prefetch => 'bars' });
::Dwarn(${$rs3->as_query}->[0]);
$s->source('Foo')->result_class('DBIx::Class::Core');
$s->source('Foo')->set_primary_key('x');
my $rs4 = $s->resultset('Foo')->new_result({ x => 1, y => 2 })
->search_related('bars');
::Dwarn(${$rs4->as_query}->[0]);
|