-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
[Question] about nest transaction? #146
Comments
Nested transaction were indeed supported but it needed expensive zones in all situation. One solution is to pass the transaction object class ClassroomProvider {
Future<Classroom> insert(Classroom room) async {
return database.transaction((txn) async {
await _teacherProvider.txnInsert(txn, room.getTeacher());
await _studentProvider.txnBulkInsert(
txn, room.getStudents()); // nest transaction here
// Insert room last to save the teacher and students ids
room.id = await txn.insert(tableClassroom, room.toMap());
return room;
});
}
}
class TeacherProvider {
Future<Teacher> insert(Teacher teacher) =>
database.transaction((txn) => txnInsert(txn, teacher));
Future<Teacher> txnInsert(Transaction txn, Teacher teacher) async {
teacher.id = await txn.insert(tableTeacher, teacher.toMap());
return teacher;
}
}
class StudentProvider {
Future<List<Student>> bulkInsert(List<Student> students) =>
database.transaction((txn) => txnBulkInsert(txn, students));
Future<List<Student>> txnBulkInsert(
Transaction txn, List<Student> students) async {
for (var student in students) {
student.id = await txn.insert(tableStudent, student.toMap());
}
return students;
}
} |
@alextekartik In additional, has any unit test or example for nest transaction? like this? database.transaction((txn1) async {
await database.transaction((txn2) async {
});
});
|
Nested transaction are not supported. SQLite does not support it. Inside a transaction you should not used the database object. |
Thanks your reply. You can close this issue now. @Other_people_that_prefer_nested_transaction: sqlfiltebrite is my flutter pkg that base on tekartik/sqflite and rxdart. And it support a simulation of the nest transaction. |
Hello dev:
I have a code that get into trouble about
nest transaction
like below. Could you give me some suggestion?As we known in README:
But the above code
use the database object in a transaction to access the database
😭 !!!In additional, has any unit test or example for nest transaction?
The text was updated successfully, but these errors were encountered: