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 select_single insert update update_single delete delete_single)) {
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 has implicit_arguments => (is => 'ro');
19 method new_select_command ($args) {
20 die "$self->has_select_sql" unless $self->has_select_sql;
21 $self->raw_store->new_stream_command(
23 $self->_unwrap_args_for(select => $args),
24 $self->select_column_order
28 method new_select_single_command ($args) {
29 die "$self->has_select_single_sql" unless $self->has_select_single_sql;
30 $self->raw_store->new_row_command(
31 $self->select_single_sql,
32 $self->_unwrap_args_for(select_single => $args),
33 $self->select_column_order
37 method _unwrap_args_for ($type, $args) {
38 if (my $implicit = $self->implicit_arguments) {
39 $args = { %$implicit, %$args };
41 [ @{$args}{@{$self->${\"${type}_argument_order"}}} ]
44 method _new_command ($builder, $type, $args) {
45 my $has_meth = "has_${type}_sql";
46 die "${self}->${has_meth}" unless $self->$has_meth;
48 $self->${\"${type}_sql"},
49 $self->_unwrap_args_for($type => $args),
53 method _new_call_command ($type, $args) {
55 sub { shift->raw_store->new_call_command(@_) },
60 method new_insert_command ($args) {
61 my $builder = $self->insert_command_constructor;
63 ? $self->_new_command($builder => insert => $args)
64 : $self->_new_call_command(insert => $args);
67 method new_update_command ($args) {
68 $self->_new_call_command(update => $args);
71 method new_delete_command ($args) {
72 $self->_new_call_command(delete => $args);
75 method new_update_single_command ($args) {
76 $self->_new_call_command(update_single => $args);
79 method new_delete_single_command ($args) {
80 $self->_new_call_command(delete_single => $args);
83 __PACKAGE__->meta->make_immutable;