-
Hi guys, I want to expose you my problem that might already have a solution, I don't know. Let's suppose I have two methods:
I have only found the method I don't know if this makes sense to you. Is there way to obtain this behavior with your library? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 16 replies
-
That's a good question. What I typically do is pass the transaction object along to any other methods that need it. In your example, it would look like this: Future<void> methodA(SqliteWriteContext tx) async {
// (insert, update, delete) on tx
}
Future<void> methodB() async {
await _dbContext.executeInTransaction((tx) async {
await methodA(tx);
// (insert, update, delete)
}
} If you also need Future<void> methodA() async {
await _dbContext.executeInTransaction((tx) async {
await methodAWithTx(tx);
}
}
Future<void> methodAWithTx(SqliteWriteContext tx) async {
// (insert, update, delete) on tx
}
Future<void> methodB() async {
await _dbContext.executeInTransaction((tx) async {
await methodAWithTx(tx);
// (insert, update, delete)
}
} There isn't a nice way currently to automatically start a transaction when not in one yet (there may be a workaround), but I've found in most cases it's better to be explicit about whether a method is called inside a transaction, or starts its own transaction. |
Beta Was this translation helpful? Give feedback.
-
Hi Ralf, is there a way to check if a transaction has been closed (for example for an automatic rollback)? Thanks! |
Beta Was this translation helpful? Give feedback.
Performance is tricky, and I can't tell why it would be slower without seeing a specific example.
If you were already using
sqflite_common_ffi
, many operations would have similar performance between the two libraries. I did a blog post a while back comparing performance between different libraries - that may give you a starting point for the general performance you should expect:https://www.powersync.co/blog/flutter-database-comparison-sqlite-async-sqflite-objectbox-isar
Going off those benchmarks: