PawsX-DynamoDB-DocumentClient
view release on metacpan or search on metacpan
lib/PawsX/DynamoDB/DocumentClient.pm view on Meta::CPAN
sub scan {
my ($self, %args) = @_;
my $command_class = 'PawsX::DynamoDB::DocumentClient::Scan';
$self->_run_command($command_class, %args);
}
sub update {
my ($self, %args) = @_;
my $command_class = 'PawsX::DynamoDB::DocumentClient::Update';
$self->_run_command($command_class, %args);
}
sub _run_command {
my ($self, $command_class, %args) = @_;
my $return_paws_output = delete $args{return_paws_output} || 0;
require_module($command_class);
my $service = $self->{dynamodb};
my %service_args = $command_class->transform_arguments(%args);
my $output = $command_class->run_service_command($service, %service_args);
return $output if $return_paws_output;
return $command_class->transform_output($output);
}
1;
__END__
=encoding utf-8
=head1 NAME
PawsX::DynamoDB::DocumentClient - a simplified way of working with AWS DynamoDB items that uses Paws under the hood.
=head1 SYNOPSIS
use PawsX::DynamoDB::DocumentClient;
my $dynamodb = PawsX::DynamoDB::DocumentClient->new();
$dynamodb->put(
TableName => 'users',
Item => {
user_id => 24,
email => 'bob@example.com',
roles => ['admin', 'finance'],
},
);
my $user = $dynamodb->get(
TableName => 'users',
Key => {
user_id => 24,
},
);
=head1 DESCRIPTION
Paws (in this author's opinion) is the best and most up-to-date way of working with AWS. However, reading and writing DynamoDB items via Paws' low-level API calls can involve a lot of busy work formatting your data structures to include DynamoDB type...
This module simplifies some DynamoDB operations by automatically converting back and forth between simpler Perl data structures and the request/response data structures used by Paws.
For more information about how types are mananged, see L<Net::Amazon::DynamoDB::Marshaler>.
This module is based on a similar class in the L<AWS JavaScript SDK|http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html>.
=head2 outputs
By default, the methods below return plain values (or nothing) that make normal use cases simpler, as opposed to the output objects that Paws generates. For example, get() returns a hashref of the item's data, as opposed to a L<Paws::DynamoDB::GetIte...
For use cases where you need more extensive output data, every method supports a return_paws_output flag, which will return the Paws object instead.
my $item = $dynamodb->get(
TableName => 'users',
Key => {
user_id => 1000,
},
);
# $item looks like { user_id => 1000, email => 'foo@bar.com', ... }
my $output = $dynamodb->get(
TableName => 'users',
Key => {
user_id => 1000,
},
return_paws_output => 1,
);
# $output isa Paws::DynamoDB::GetItemOutput
=head2 force_type
All methods take in an optional force_type parameter, which gets passed to L<Net::Amazon::DynamoDB::Marshaler> for when you need to override its default typing. See the description of force_type in that module's documentation for more details.
=head1 METHODS
=head2 new
my $dynamodb = PawsX::DynamoDB::DocumentClient->new(
region => 'us-east-1',
);
This class method returns a new PawsX::DynamoDB::DocumentClient object. It accepts the following parameters:
=head3 paws
A Paws object to use to create the Paws::DynamoDB service object. Optional. Available in case you need to custom configuration of Paws (e.g. authentication).
=head3 dynamodb
Alternatively, you can provide a Paws::DynamoDB service object directly if you have one. Optional. If given, the 'paws' parameter will be ignored.
=head3 region
The AWS region to use when creating the Paws::DynamoDB service object. If not specified, will try to grab from the AWS_DEFAULT_REGION environment variable. Will be ignored if the object is constructed with a dynamodb object, or with a paws object tha...
If the constructor can't figure out what region to use, an error will be thrown.
=head2 batch_get
( run in 1.075 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )