1 package DBIx::Data::Store::CRUD;
5 use DBIx::Data::Stream::STH;
9 bless({ %{$_[0]} }, ref($proto)||$proto);
12 sub _sql { shift->{sql} }
13 sub _raw { shift->{raw} }
14 sub _append_args { shift->{append_args} }
18 my ($run_type, $sql_type, $args) = @_;
19 my $sql = $self->_sql->{$sql_type}||die "No such sql type ${sql_type}";
20 if (my $append = $self->_append_args) {
21 $args = [ @{$args||[]}, @$append ];
23 $self->_raw->${\"run_${run_type}"}($sql, $args);
26 sub flatten { @{shift->_run('rowset', 'select_all', @_)} }
28 sub to_stream { shift->_run('rowstream', 'select_all', @_) }
30 sub clear { shift->_run('row','delete_all',@_) }
32 sub get { shift->_run('row','select_one',@_) }
36 $self->_run('row','update_one', [ @{$_[1]}, @{$_[0]} ]);
39 # returning args ($_[0]) if we don't get anything back saves us needing
40 # to emulate INSERT RETURNING in the case where no columns are supplied
41 # by the database. I think this is a feature.
43 sub add { shift->_run('row','insert_one',@_)||$_[0] }
45 sub remove { shift->_run('row','delete_one',@_) }