-
Notifications
You must be signed in to change notification settings - Fork 109
Description
Hi there, I'm a Rails developer just starting out with Flutter and your SQFEntity lib with a test project.
Using:
sqfentity: ^2.3.0
sqfentity_gen: ^2.3.0
I'm pulling in JSON data from an authenticated API via custom networking code, then simply trying to save that data into the db.
Here's the execution code with some comments:
var json = await NetworkManager.authedGet('support_items');
var test = await Task().select().toList();
print("Tasks before upsert: ${test.length}");
var tasks = await Task.fromMapList(json);
print("Tasks to save: ${tasks.length}");
//// Below properly saves records
for (var task in tasks) {
task.upsert();
}
//// Below doesn't change anything
// var result = await Task().upsertAll(tasks, continueOnError: true);
// print(result.commitResult?.join('\n'));
// print(result);
test = await Task().select().toList();
print("Tasks after upsert: ${test.length}");
What I want/expected the correct code to be:
var json = await NetworkManager.authedGet('support_items');
var tasks = await Task.fromMapList(json);
await Task().upsertAll(tasks);
The result using the commented out upsertAll() is the following:
flutter: Tasks before upsertAll: 0
flutter: Tasks to save: 28
flutter: null
flutter: Result: OK! Successful
flutter: Tasks after upsertAll: 0
And when using the for loop with upsert() I get:
flutter: Tasks before upsert: 0
flutter: Tasks to save: 28
flutter: Tasks after upsert: 28
Considering the result.commitResult is null when using upsertAll(), and it only gives these if it could create a new batch, it looks like this might be a problem with the batching?
Specifically, this conditional here: https://github.com/hhtokpinar/sqfEntity/blob/master/sqfentity/lib/sqfentity.dart#L399
It looks like if the batch couldn't be generated, it just returns a true result?
That doesn't seem correct to me. If it can't generate a new batch, then it should wait for that batch to finish before creating a new one. Or throw an exception. Or at the very least, return a failed result.