From: Matt S Trout Date: Sun, 29 Aug 2010 01:26:08 +0000 (+0100) Subject: allow coderef in place of SQL for complex commands X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Data-Store.git;a=commitdiff_plain;h=937bf544223e9699f30e0dc397e3b0f1e5f7b654 allow coderef in place of SQL for complex commands --- diff --git a/lib/DBIx/Data/Store/Raw.pm b/lib/DBIx/Data/Store/Raw.pm index 82885a9..9a5b269 100644 --- a/lib/DBIx/Data/Store/Raw.pm +++ b/lib/DBIx/Data/Store/Raw.pm @@ -33,10 +33,15 @@ sub run_rowstream { } sub _exec_calling { - my ($self, $call, @sth_args) = @_; - $self->_exec(sub { - $self->_sth_for($_[0], @sth_args)->$call - }); + my ($self, $sth_method, $to_call, $sth_args) = @_; + + $self->_exec( + ref($to_call) eq 'CODE' + ? sub { $self->$to_call($sth_method, $_[0], $sth_args) } + : sub { + $self->_sth_for($_[0], $to_call, $sth_args)->$sth_method + } + ); } sub _exec { diff --git a/t/crud.t b/t/crud.t index bf762b5..71214c1 100644 --- a/t/crud.t +++ b/t/crud.t @@ -46,7 +46,11 @@ sub make_store { select_all => 'SELECT id, name FROM names', delete_all => 'DELETE FROM names', select_one => 'SELECT id, name FROM names WHERE id = ?', - insert_one => 'INSERT INTO names (name) VALUES (?)',# RETURNING (id)', + insert_one => sub { + my ($store, undef, $dbh, $args) = @_; + $store->_sth_for($dbh, 'INSERT INTO names (name) VALUES (?)', $args); + [ $dbh->last_insert_id(undef,undef,undef,undef) ]; + }, update_one => 'UPDATE names SET name = ? WHERE id = ?', delete_one => 'DELETE FROM names WHERE id = ?', },