}
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 {
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 = ?',
},