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

[feature] Dao independent transactions #340

Open
otopba opened this issue May 24, 2020 · 6 comments
Open

[feature] Dao independent transactions #340

otopba opened this issue May 24, 2020 · 6 comments
Labels
feature Request and implementation of a feature (release drafter)

Comments

@otopba
Copy link

otopba commented May 24, 2020

Sometimes you need to make a transaction that will work with several DAO or will have a lot of logic. I would like to have separate methods for starting and ending a transaction. Now, having only an annotation, this is not possible

Thank you!

@vitusortner
Copy link
Collaborator

What would you think of something similar to the following? We could add a member function on FloorDatabse that can be used for executing DAO functions inside a transaction.

database.runInTransaction(() {
  // DAO invocations
});

@vitusortner vitusortner added the feature Request and implementation of a feature (release drafter) label May 27, 2020
@otopba
Copy link
Author

otopba commented May 27, 2020

@vitusortner
Yes, it can be done that way. But then how can we say that the transaction is successful or not? If there was no exception, is the transaction successful?

@mqus
Copy link
Collaborator

mqus commented Jun 14, 2020

Usually, yes. I don't know why that shouldn't be the case.

@mqus
Copy link
Collaborator

mqus commented Jun 14, 2020

I want to add, though, that if we want to add support for database.runInTransaction then we will have to give the inner function its own database (backed by the transaction). So the actual invocation would look like this:

database.runInTransaction((transactionDB) async {
  // DAO invocations
  transactionDB.someDao.findEntriesInTable("value");
});

or this (just using a function reference instead of a closure):

database.runInTransaction(withTransaction);

Future<void> withTransaction(MyDB transactionDB) async{
  // DAO invocations
  transactionDB.someDao.findEntriesInTable("value");
}

This would fit nicely into #360, too.

@NikoBoerger
Copy link

Are there any updates on that? :)

@vitusortner
Copy link
Collaborator

Unluckily not. In case you're interested, feel free to open a PR that implements the desired functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Request and implementation of a feature (release drafter)
Development

No branches or pull requests

4 participants