Skip to content

Commit

Permalink
Merge branch 'master' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalybibikov committed Apr 16, 2024
2 parents 3575af4 + 36e8f84 commit b471423
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ jobs:
docker-compose build
- name: Run tests
run: docker-compose up --exit-code-from tests
run: docker-compose up --exit-code-from tests tests localstack

- name: Run tests
run: docker-compose up --exit-code-from unittests unittests

- name: Upload TRX test results
uses: actions/upload-artifact@v2
if: always() # This ensures it runs even if the previous steps fail
Expand Down
111 changes: 110 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,110 @@
# DynamoDBv2.Transactions
# DynamoDBv2.Transactions

DynamoDBv2.Transactions is a .NET library that provides a robust wrapper around the Amazon DynamoDB low-level API, enabling easy and efficient management of transactions for batch operations. This library is designed to simplify complex transactional logic and ensure data consistency across your DynamoDB operations.

Test Results: ![Badge](https://camo.githubusercontent.com/7a1b0b1a230ee19f14cef6ac1970103f931c61e06e96866a0c7a45c68bfd8755/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f362f362d5041535345442d627269676874677265656e2e737667) ![Badge](https://camo.githubusercontent.com/e6f58b5667bf820dd34d07762b5f0232f3d27d6fde052988c9e07af61ab1448e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f34312f34312d5041535345442d627269676874677265656e2e737667)


## Features

- **Transactional Operations**: Supports `CreateOrUpdate`, `Delete`, and `Patch` operations within transactions.
- **Error Handling**: Gracefully handles transaction failures and rollbacks.
- **Versioning Support**: Automatic handling of version increments for transactional integrity.
- **Easy Integration**: Seamlessly integrates with existing DynamoDB setups.
- **Asynchronous API**: Fully asynchronous API for optimal performance.

## Installation

You can install the DynamoDBv2.Transactions library via NuGet Package Manager. Run the following command in your Package Manager Console:

```bash
Install-Package DynamoDBv2.Transactions
```

## Quick Start

To get started with DynamoDBv2.Transactions, you'll need to set up an instance of `TransactionalWriter` using an `ITransactionManager`, which is responsible for executing the transactions against your DynamoDB instance.

### Prerequisites

Ensure you have the AWS SDK for .NET configured in your project, with access to Amazon DynamoDB.

### Example Usage

Here's a quick example to show you how to use the `TransactionalWriter` to perform a transaction:

```csharp
using DynamoDBv2.Transactions;

// Initialize the DynamoDB client
var client = new AmazonDynamoDBClient();

// Setup transaction manager and writer
var transactionManager = new TransactionManager(client);
var writer = new TransactionalWriter(transactionManager);

var userId = Guid.NewGuid().ToString();
var testItem = new TestTable
{
UserId = userId,
SomeDecimal = 123.45m,
SomeDate = DateTime.UtcNow,
SomeInt = 123
};

// Perform transaction
await using (writer)
{
writer.CreateOrUpdate(testItem);
}

// Load and verify
var dbContext = new DynamoDBContext(client);
var data = await dbContext.LoadAsync<TestTable>(userId);
Console.WriteLine($"Item saved with UserId: {data.UserId}");
```

## Running Tests

To run integration tests, ensure you have a test instance of DynamoDB available. Tests are written using xUnit and should be configured to interact directly with your database:

```csharp
// Example test
[Fact]
public async Task SaveDataAndRetrieve()
{
var writer = new TransactionalWriter(new TransactionManager(_fixture.Db.Client));
var userId = Guid.NewGuid().ToString();
var testItem = new TestTable
{
UserId = userId,
SomeInt = 123
};

await using (var writer = new TransactionalWriter(new TransactionManager(_fixture.Db.Client)))
{
writer.CreateOrUpdate(testItem);
}

var retrievedItem = await _fixture.Db.Context.LoadAsync<TestTable>(userId);
Assert.NotNull(retrievedItem);
}
```

## Contributing

When creating PRs, please review the following guidelines:

- [ ] The action code does not contain sensitive information.
- [ ] At least one of the commit messages contains the appropriate `+semver:` keywords listed under [Incrementing the Version] for major and minor increments.
- [ ] The action has been recompiled. See [Recompiling Manually] for details.
- [ ] The README.md has been updated with the latest version of the action. See [Updating the README.md] for details.


## License

Copyright &copy; 2024, Extend Health, LLC. Code released under the [MIT license](LICENSE).

## Contact

Your Name - [bibikovvitaly@gmail.com]

0 comments on commit b471423

Please sign in to comment.