-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: bring back sqflite dependency, improve database initialization
- Loading branch information
Showing
15 changed files
with
153 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
import 'package:drift/drift.dart'; | ||
import '../database.dart'; | ||
|
||
Never _unsupported() { | ||
throw UnsupportedError('No suitable database implementation was found on this platform.'); | ||
} | ||
|
||
// Depending on the platform the app is compiled to, the following stubs will | ||
// be replaced with the methods in native.dart or web.dart | ||
AppDatabase constructDb() => throw UnimplementedError(); | ||
|
||
Future<void> validateDatabaseSchema(GeneratedDatabase database) async { | ||
_unsupported(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,22 @@ | ||
import 'package:flutter/foundation.dart'; | ||
|
||
import 'package:drift/drift.dart'; | ||
import 'package:drift/wasm.dart'; | ||
import '../database.dart'; | ||
|
||
Future<void> validateDatabaseSchema(GeneratedDatabase database) async { | ||
// Unfortunately, validating database schemas only works for native platforms | ||
// right now. | ||
// As we also have migration tests (see the `Testing migrations` section in | ||
// the readme of this example), this is not a huge issue. | ||
} | ||
|
||
DatabaseConnection connectOnWeb() { | ||
return DatabaseConnection.delayed(Future(() async { | ||
final result = await WasmDatabase.open( | ||
databaseName: 'thunder', // prefer to only use valid identifiers here | ||
sqlite3Uri: Uri.parse('sqlite3.wasm'), | ||
driftWorkerUri: Uri.parse('drift_worker.dart.js'), | ||
); | ||
|
||
if (result.missingFeatures.isNotEmpty) { | ||
// Depending how central local persistence is to your app, you may want | ||
// to show a warning to the user if only unrealiable implemetentations | ||
// are available. | ||
print('Using ${result.chosenImplementation} due to missing browser ' | ||
'features: ${result.missingFeatures}'); | ||
} | ||
|
||
return result.resolvedExecutor; | ||
})); | ||
} | ||
// This method validates that the actual schema of the opened database matches | ||
// the tables, views, triggers and indices for which drift_dev has generated | ||
// code. | ||
// | ||
// Validating the database's schema after opening it is generally a good idea, | ||
// since it allows us to get an early warning if we change a table definition | ||
// without writing a schema migration for it. | ||
// | ||
// For details, see: https://drift.simonbinder.eu/docs/advanced-features/migrations/#verifying-a-database-schema-at-runtime | ||
if (kDebugMode) { | ||
// TODO: Add validation when updating to drift 2.22 | ||
// final sqlite = await WasmSqlite3.loadFromUrl(Uri.parse('/sqlite3.wasm')); | ||
// sqlite.registerVirtualFileSystem(InMemoryFileSystem(), makeDefault: true); | ||
|
||
AppDatabase constructDb() { | ||
return AppDatabase(connectOnWeb()); | ||
// await VerifySelf(database).validateDatabaseSchema(sqlite3: sqlite); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.