Skip to content

Commit

Permalink
Exposes core private functionality in data layer, while annotating with
Browse files Browse the repository at this point in the history
  • Loading branch information
matuella committed Mar 29, 2021
1 parent b122aeb commit af6189d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 3 additions & 1 deletion lib/data/database_repository.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';
import 'package:sembast/sembast.dart';

/// Handles the local persistence to the database
Expand Down Expand Up @@ -139,7 +140,8 @@ class DatabaseRepositoryImpl implements DatabaseRepository {
}
}

extension on DatabaseStore {
extension StoreKeys on DatabaseStore {
@visibleForTesting
String get key {
switch (this) {
case DatabaseStore.decks:
Expand Down
11 changes: 4 additions & 7 deletions lib/data/sembast_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ import 'package:sembast/sembast_io.dart';
const _schemaVersion = 1;
const _dbName = 'memo_sembast.db';

/// Opens this application's [Database], creating a new one if non-existing
/// Opens this application's [Database], creating a new one if nonexistent
Future<Database> openDatabase() async {
final dir = await getApplicationDocumentsDirectory();
// Make sure that the application documents directory exists
await dir.create(recursive: true);

final dbPath = path.join(dir.path, _dbName);

return databaseFactoryIo.openDatabase(dbPath, version: _schemaVersion, onVersionChanged: _applyMigrations);
return databaseFactoryIo.openDatabase(dbPath, version: _schemaVersion, onVersionChanged: applyMigrations);
}

Future<void> _applyMigrations(Database db, int oldVersion, int newVersion) async {
if (oldVersion == newVersion) {
return SynchronousFuture(null);
}

@visibleForTesting
Future<void> applyMigrations(Database db, int oldVersion, int newVersion) async {
// Call the necessary migrations in order
}

Expand Down

0 comments on commit af6189d

Please sign in to comment.