Skip to content

Commit

Permalink
Close local database
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Jan 21, 2025
1 parent 1aa784b commit ecae6e8
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions data/lib/services/local_media_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,35 +126,38 @@ class LocalMediaService {
Future<void> addToCleanUpMediaDatabase({
required List<CleanUpMedia> medias,
}) async {
final database = await openCleanUpDatabase();
final batch = database.batch();
final db = await openCleanUpDatabase();
final batch = db.batch();
for (CleanUpMedia media in medias) {
batch.insert(
LocalDatabaseConstants.cleanUpTable,
media.toJson(),
);
}
await batch.commit();
await db.close();
}

Future<void> removeFromCleanUpMediaDatabase(List<String> ids) async {
final database = await openCleanUpDatabase();
await database.delete(
final db = await openCleanUpDatabase();
await db.delete(
LocalDatabaseConstants.cleanUpTable,
where: 'id IN (${List.filled(ids.length, '?').join(',')})',
whereArgs: ids,
);
await db.close();
}

Future<void> clearCleanUpMediaDatabase() async {
final database = await openCleanUpDatabase();
await database.delete(LocalDatabaseConstants.cleanUpTable);
final db = await openCleanUpDatabase();
await db.delete(LocalDatabaseConstants.cleanUpTable);
await db.close();
}

Future<List<CleanUpMedia>> getCleanUpMedias() async {
final database = await openCleanUpDatabase();

final res = await database.query(LocalDatabaseConstants.cleanUpTable);
final db = await openCleanUpDatabase();
final res = await db.query(LocalDatabaseConstants.cleanUpTable);
await db.close();
return res.map((e) => CleanUpMedia.fromJson(e)).toList();
}

Expand Down

0 comments on commit ecae6e8

Please sign in to comment.