has _store => (is => 'ro', required => 1, init_arg => 'store');
-has _column_order => (is => 'ro', required => 1, init_arg => 'column_order');
-
has _class => (is => 'ro', predicate => '_has_class');
has _member_cache => (is => 'rw', lazy_build => 1);
}
method _inflate ($raw) {
- my @order = @{$self->_column_order};
- my %final;
- @final{@order} = @$raw;
- bless(\%final, $self->_class) if $self->_has_class;
- \%final;
+ bless($raw, $self->_class) if $self->_has_class;
+ $raw;
}
method flatten {
);
}
-method new_row_command ($sql, $args) {
+method new_row_command ($sql, $args, $column_order) {
return DBIx::Data::Store::Command::Row->new(
run => $sql, with => $args, against => $self->connection
);
}
-method new_stream_command ($sql, $args) {
+method new_stream_command ($sql, $args, $column_order) {
return DBIx::Data::Store::Command::Stream->new(
- run => $sql, with => $args, against => $self->connection
+ run => $sql, with => $args, against => $self->connection,
+ column_order => $column_order
);
}
foreach my $type (qw(select insert update delete)) {
has "${type}_sql" => (is => 'ro', predicate => "has_${type}_sql");
+ has "${type}_argument_order" => (is => 'ro', default => sub { [] });
}
+has "select_column_order" => (is => 'ro');
+
method new_select_command ($args) {
die "$self->has_select_sql" unless $self->has_select_sql;
- $self->raw_store->new_stream_command($self->select_sql, $args);
+ $self->raw_store->new_stream_command(
+ $self->select_sql,
+ $self->_unwrap_args_for(select => $args),
+ $self->select_column_order
+ );
+}
+
+method _unwrap_args_for ($type, $args) {
+ [ @{$args}{@{$self->${\"${type}_argument_order"}}} ]
+}
+
+method _new_call_command ($type, $args) {
+ my $has_meth = "has_${type}_sql";
+ die "${self}->${has_meth}" unless $self->$has_meth;
+ $self->raw_store->new_call_command(
+ $self->${\"${type}_sql"},
+ $self->_unwrap_args_for($type => $args)
+ );
}
method new_insert_command ($args) {
- die "$self->has_insert_sql" unless $self->has_insert_sql;
- $self->raw_store->new_call_command($self->insert_sql, $args);
+ $self->_new_call_command(insert => $args);
}
method new_update_command ($args) {
- die "$self->has_update_sql" unless $self->has_update_sql;
- $self->raw_store->new_call_command($self->update_sql, $args);
+ $self->_new_call_command(update => $args);
}
method new_delete_command ($args) {
- die "$self->has_delete_sql" unless $self->has_delete_sql;
- $self->raw_store->new_call_command($self->delete_sql, $args);
+ $self->_new_call_command(delete => $args);
}
__PACKAGE__->meta->make_immutable;
use Carp qw(carp);
use Method::Signatures::Simple;
+has 'column_order' => (is => 'ro', required => 1);
+
method execute {
- my $sth = $self->_new_active_sth;
- my @row = $sth->fetchrow_array;
- my @nextrow = $sth->fetchrow_array if @row;
- if(@row && @nextrow) {
+ my $result = (my $stream = DBIx::Data::Stream::STH->new(
+ sth => $self->_new_active_sth, column_order => $self->column_order,
+ ))->next;
+ if ($stream->next) {
carp "Query returned more than one row - did you want a stream command?";
}
- # Need to call finish() to work round broken DBDs
- $sth->finish();
- return \@row;
+ return $result;
}
with 'DBIx::Data::Store::Command';
use Method::Signatures::Simple;
use DBIx::Data::Stream::STH;
+has 'column_order' => (is => 'ro', required => 1);
+
method execute {
- my $sth = $self->_new_active_sth;
DBIx::Data::Stream::STH->new(
- sth => $sth
+ sth => $self->_new_active_sth, column_order => $self->column_order,
);
}
has 'sth' => (is => 'ro', required => 1, clearer => '_clear_sth');
+has '_column_order' => (is => 'ro', required => 1, init_arg => 'column_order');
+
method next {
my $sth = $self->sth;
return unless $sth;
# {Active} only means that there *may* be more results to fetch
if ($sth->{Active} and my @next = $self->sth->fetchrow_array) {
- return \@next;
+ my %next; @next{@{$self->_column_order}} = @next;
+ return \%next;
}
$sth->finish;
# prepare_cached might recycle it now we're finished so get rid of it
store => DBIx::Data::Store::CRUD->new(
raw_store => DBIx::Data::Store->connect($dsn),
select_sql => q{SELECT id, name FROM person},
+ select_column_order => [ qw(id name) ],
),
- column_order => [ qw(id name) ],
);
}