1 package DBIx::Data::Store::CRUD;
4 use Method::Signatures::Simple;
6 has raw_store => (is => 'ro', required => 1); # DBIx::Data::Store object
8 foreach my $type (qw(select insert update delete)) {
9 has "${type}_sql" => (is => 'ro', predicate => "has_${type}_sql");
10 has "${type}_argument_order" => (is => 'ro', default => sub { [] });
13 has 'insert_command_constructor' => (is => 'ro');
15 has "select_column_order" => (is => 'ro');
17 method new_select_command ($args) {
18 die "$self->has_select_sql" unless $self->has_select_sql;
19 $self->raw_store->new_stream_command(
21 $self->_unwrap_args_for(select => $args),
22 $self->select_column_order
26 method _unwrap_args_for ($type, $args) {
27 [ @{$args}{@{$self->${\"${type}_argument_order"}}} ]
30 method _new_command ($builder, $type, $args) {
31 my $has_meth = "has_${type}_sql";
32 die "${self}->${has_meth}" unless $self->$has_meth;
34 $self->${\"${type}_sql"},
35 $self->_unwrap_args_for($type => $args),
39 method _new_call_command ($type, $args) {
41 sub { shift->raw_store->new_call_command(@_) },
46 method new_insert_command ($args) {
47 my $builder = $self->insert_command_constructor;
49 ? $self->_new_command($builder => insert => $args)
50 : $self->_new_call_command(insert => $args);
53 method new_update_command ($args) {
54 $self->_new_call_command(update => $args);
57 method new_delete_command ($args) {
58 $self->_new_call_command(delete => $args);
61 __PACKAGE__->meta->make_immutable;