Skip to content

Add support for DynamoDBAutoGeneratedTimestampAttribute and DynamoDbUpdateBehaviorAttribute #3892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: development
Choose a base branch
from

Conversation

irina-herciu
Copy link
Contributor

@irina-herciu irina-herciu commented Jun 23, 2025

Add

  • support for the [DynamoDBAutoGeneratedTimestamp] attribute to the .NET SDK for DynamoDB, enabling automatic setting of timestamp fields during save operations. This feature aligns with the Java SDK's @DynamoDbAutoGeneratedTimestampAttribute.
  • support for [DynamoDbUpdateBehavior] attribute to the .NET SDK for DynamoDB, enabling update behavior for a property when performing DynamoDB update operations. This feature aligns with the Java SDK's @DynamoDbUpdateBehavior.

Description

  • New Attributes: [DynamoDBAutoGeneratedTimestamp] and [DynamoDbUpdateBehavior]

    • [DynamoDBAutoGeneratedTimestamp] Automatically sets the property to the current UTC timestamp (DateTime.UtcNow) on item save.
    • [DynamoDbUpdateBehavior] Specifies the update behavior for a property when performing DynamoDB update operations. This attribute can be used to control whether a property is always updated, only updated if not null.
  • Update Behavior Modes:

    • IfNotExists: Set the value only when the item is created.
    • Always: Set the value on both create and update.
  • Usage:

    class Order
    {
        [DynamoDBHashKey]
        public string Id { get; set; }
    
        [DynamoDBAutoGeneratedTimestamp]
        [DynamoDbUpdateBehavior(UpdateBehavior.IfNotExists)]
        public DateTime CreatedAt { get; set; }
    
        [DynamoDBAutoGeneratedTimestamp]
        [DynamoDBProperty(StoreAsEpoch = true)]
        public DateTime? UpdatedAt { get; set; }
    }

Motivation and Context

Testing

unit and integration tests added

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

@irina-herciu irina-herciu changed the title Add support for DynamoDBAutoGeneratedTimestampAttribute that sets current timestamp during persistence operations. Add support for DynamoDBAutoGeneratedTimestampAttribute and DynamoDbUpdateBehaviorAttribute Jul 7, 2025
@irina-herciu irina-herciu marked this pull request as ready for review July 7, 2025 15:30
@normj normj self-requested a review July 15, 2025 00:38
Copy link
Member

@normj normj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the code paths updated for the batch and transact write operations.

@irina-herciu
Copy link
Contributor Author

I don't see the code paths updated for the batch and transact write operations.

Transact write operation is updated and there is an integration test added - Test_AutoGeneratedTimestampAttribute_TransactWrite_Simple

Batch write operation does not offer support for autogenerated values as the operation does not support update expressions and this behavior is consistent with the Java SDK as well as DynamoDBVersionAttribute.

@irina-herciu
Copy link
Contributor Author

after testing, looks like Batch write operation on Java SDK it offers support for autogenerated timestamps and ignores the DynamoDbUpdateBehavior. I will update the implementation to cover this.

@irina-herciu
Copy link
Contributor Author

autogenerated timestamp implementation updated to cover also batch write operation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants