feat: Implement batch insertion for Pokémon and utilize it for more efficient initial data synchronization.
This commit is contained in:
@@ -43,6 +43,21 @@ class PokedexDatabase {
|
||||
onDatabaseUpdate.value++;
|
||||
}
|
||||
|
||||
// Méthode qui permet d'insérer plusieurs Pokémon d'un coup (plus performant)
|
||||
static Future<void> batchInsertPokemon(List<Pokemon> pokemonList) async {
|
||||
Database db = await getDatabase();
|
||||
Batch batch = db.batch();
|
||||
for (var pokemon in pokemonList) {
|
||||
batch.insert(
|
||||
'pokemon',
|
||||
pokemon.toJson(),
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
}
|
||||
await batch.commit(noResult: true);
|
||||
onDatabaseUpdate.value++;
|
||||
}
|
||||
|
||||
// Méthode qui permet de récupérer la liste des pokémons dans la base de données
|
||||
static Future<List<Pokemon>> getPokemonList() async {
|
||||
Database database = await getDatabase();
|
||||
|
||||
Reference in New Issue
Block a user