An Interest In:
Web News this Week
- November 3, 2024
- November 2, 2024
- November 1, 2024
- October 31, 2024
- October 30, 2024
- October 29, 2024
- October 28, 2024
February 12, 2024 02:34 am GMT
Original Link: https://dev.to/aws/20-days-of-dynamodb-day-19-partiql-batch-operations-mg6
[20 Days of DynamoDB] Day 19 - PartiQL Batch Operations
Posted: 12/Feb/2024
You can use batched operations with PartiQL as well, thanks to BatchExecuteStatement
. It allows you to batch reads as well as write requests.
Here is an example (note that you cannot mix both reads and writes in a single batch):
//read statements client.BatchExecuteStatement(context.Background(), &dynamodb.BatchExecuteStatementInput{ Statements: []types.BatchStatementRequest{ { Statement: aws.String("SELECT * FROM url_metadata where shortcode=?"), Parameters: []types.AttributeValue{ &types.AttributeValueMemberS{Value: "abcd1234"}, }, }, { Statement: aws.String("SELECT * FROM url_metadata where shortcode=?"), Parameters: []types.AttributeValue{ &types.AttributeValueMemberS{Value: "qwer4321"}, }, }, }, }) //separate batch for write statements client.BatchExecuteStatement(context.Background(), &dynamodb.BatchExecuteStatementInput{ Statements: []types.BatchStatementRequest{ { Statement: aws.String("INSERT INTO url_metadata value {'longurl':?,'shortcode':?, 'active': true}"), Parameters: []types.AttributeValue{ &types.AttributeValueMemberS{Value: "https://github.com/abhirockzz"}, &types.AttributeValueMemberS{Value: uuid.New().String()[:8]}, }, }, { Statement: aws.String("UPDATE url_metadata SET active=? where shortcode=?"), Parameters: []types.AttributeValue{ &types.AttributeValueMemberBOOL{Value: false}, &types.AttributeValueMemberS{Value: "abcd1234"}, }, }, { Statement: aws.String("DELETE FROM url_metadata where shortcode=?"), Parameters: []types.AttributeValue{ &types.AttributeValueMemberS{Value: "qwer4321"}, }, }, }, })
Just like BatchWriteItem
, BatchExecuteStatement
is limited to 25 statements (operations) per batch.
Recommended reading:
BatchExecuteStatement
API docs- Build faster with Amazon DynamoDB and PartiQL: SQL-compatible operations (thanks Pete Naylor !)
Original Link: https://dev.to/aws/20-days-of-dynamodb-day-19-partiql-batch-operations-mg6
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To