Skip to content

Commit

Permalink
using new SQLA::More API for insert/update/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
damil committed Dec 16, 2011
1 parent 8344813 commit 8cf7024
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
18 changes: 9 additions & 9 deletions Build.PL
Expand Up @@ -9,15 +9,15 @@ my $builder = Module::Build->new(
dist_author => 'Laurent Dami <laurent.dami AT etat.ge.ch>',
dist_version_from => 'lib/DBIx/DataModel.pm',
requires => {
'perl' => 5.008,
'Test::More' => 0,
'Carp' => 0,
'DBI' => 0,
'SQL::Abstract::More' => 0,
'Module::Build' => 0,
'Acme::Damn' => 0,
'Scalar::Util' => 0,
'Storable' => 0,
'perl' => 5.008,
'Test::More' => 0,
'Carp' => 0,
'DBI' => 0,
'SQL::Abstract::More' => 1.0,
'Module::Build' => 0,
'Acme::Damn' => 0,
'Scalar::Util' => 0,
'Storable' => 0,

# new dependencies in 2.0
'namespace::autoclean' => 0,
Expand Down
2 changes: 2 additions & 0 deletions Changes
@@ -1,5 +1,7 @@
Revision history for Perl extension DBIx::DataModel.

- using new SQLA::More API for insert/update/delete

v2.06 07.12.2011
- new method Path::opposite()

Expand Down
13 changes: 9 additions & 4 deletions lib/DBIx/DataModel/ConnectedSource.pm
Expand Up @@ -261,8 +261,11 @@ sub update {

# database request
my $schema = $self->{schema};
my @sqla_args = ($meta_source->db_from, $to_set, $where);
my ($sql, @bind) = $schema->sql_abstract->update(@sqla_args);
my ($sql, @bind) = $schema->sql_abstract->update(
-table => $meta_source->db_from,
-set => $to_set,
-where => $where,
);
$schema->_debug(do {no warnings 'uninitialized';
$sql . " / " . CORE::join(", ", @bind);});
my $method = $schema->dbi_prepare_method;
Expand Down Expand Up @@ -327,8 +330,10 @@ sub delete {

# database request
my $schema = $self->{schema};
my @sqla_args = ($meta_source->db_from, $where);
my ($sql, @bind) = $schema->sql_abstract->delete(@sqla_args);
my ($sql, @bind) = $schema->sql_abstract->delete(
-from => $meta_source->db_from,
-where => $where,
);
$schema->_debug($sql . " / " . CORE::join(", ", @bind) );
my $method = $schema->dbi_prepare_method;
my $sth = $schema->dbh->$method($sql);
Expand Down
2 changes: 1 addition & 1 deletion lib/DBIx/DataModel/Schema.pm
Expand Up @@ -15,7 +15,7 @@ use Module::Load qw/load/;
use Params::Validate qw/validate SCALAR ARRAYREF CODEREF UNDEF
OBJECT BOOLEAN/;
use Acme::Damn qw/damn/;
use SQL::Abstract::More;
use SQL::Abstract::More 1.0;

use namespace::clean;

Expand Down
9 changes: 6 additions & 3 deletions lib/DBIx/DataModel/Source/Table.pm
Expand Up @@ -71,9 +71,12 @@ sub _rawInsert {
# already cloned in Statement::insert(). But quite hard to improve :-((

# perform the insertion
my @sqla_args = ($metadm->db_from, \%values);
push @sqla_args, {returning => $options{-returning}} if $use_returning;
my ($sql, @bind) = $schema->sql_abstract->insert(@sqla_args);
my %sqla_args = (
-into => $metadm->db_from,
-values => \%values,
);
$sqla_args{-returning} = $options{-returning} if $use_returning;
my ($sql, @bind) = $schema->sql_abstract->insert(%sqla_args);
$self->schema->_debug($sql . " / " . join(", ", @bind) );
my $sth = $schema->dbh->prepare($sql);
$sth->execute(@bind);
Expand Down

0 comments on commit 8cf7024

Please sign in to comment.