Skip to content
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

Add support utility for performing Transactions #201

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

PatilShreyas
Copy link
Contributor

@PatilShreyas PatilShreyas commented May 28, 2021

Summary

  • This PR adds a utility function that supports performing SQL transactions with ease.
  • Fixed typo of a filename DataSourceExtensions.kt (Earlier its name was DataSoruceExtensions.kt).

Example Usage

Refer to the following example for the usage of transaction:

val result = dataSource.executeTransaction { connection ->
    val user = FindUserByIdQuery().query(connection, FindUserByIdParams(id))

    AddUserItemOneCommand().command(connection, AddUserItemOneParams(item1, user.id))
    AddUserItemTwoCommand().command(connection, AddUserItemTwoParams(item2, user.id))
}

// Check whether transaction is successful
val isSuccessful = result.isSuccessful

// Retrieve transaction result
val viewCount = result.get() // or `result.getOrNull()` to retrieve safely.

// Retrieve exception (if it's failed)
val error = result.errorOrNull()

Checklist

  • My changes are not breaking the existing functionality of the app.
  • I've tested the new feature on the actual environment.

@sonarcloud
Copy link

sonarcloud bot commented May 28, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

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.

1 participant