You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
...well, after debugging this for the past four hours, it's of course only 10min after I post this issue that I find a workable solution.
However, the root bug is still there (reporting that it succeeded when it didn't do anything).
When I extracted the above code out of my method I was calling from initState(), it works.
i.e:
// NetworkManager
...
static Future<bool> updateSupportItems() async {
var json = await NetworkManager.authedGet('support_items');
var tasks = await Task.fromMapList(json);
var result = await Task().upsertAll(tasks);
return result.success;
}
...
// Widget
...
void fetchItems() async {
setState(() => _loading = true);
var test = await Task().select().toList();
print("Tasks before upsert: ${test.length}");
await NetworkManager.updateSupportItems();
test = await Task().select().toList();
print("Tasks after upsert: ${test.length}");
updateItems();
}
@override
void initState() {
super.initState();
updateItems();
fetchItems();
}
...
flutter: Tasks before upsert: 0
flutter: Tasks after upsert: 28
🤷♂️
No idea why it couldn't create a batch where it originally was, but should definitely get some sort of error feedback from that, rather than claiming it succeeded.
Hi there, I'm a Rails developer just starting out with Flutter and your SQFEntity lib with a test project.
Using:
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:
What I want/expected the correct code to be:
The result using the commented out
upsertAll()
is the following:And when using the
for
loop withupsert()
I get:Considering the
result.commitResult
isnull
when usingupsertAll()
, 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.
The text was updated successfully, but these errors were encountered: