From 9553e936e3196c63f53154e7fb4891f70b56dabc Mon Sep 17 00:00:00 2001 From: MahanRahmati Date: Fri, 28 Jul 2023 16:54:14 +0330 Subject: [PATCH] feat: remove drift --- CHANGELOG.md | 1 - lib/src/database/connection/connection.dart | 5 -- lib/src/database/connection/native.dart | 40 ----------- lib/src/database/connection/unsupported.dart | 18 ----- lib/src/database/connection/web.dart | 34 --------- lib/src/database/database.dart | 15 ---- lib/src/database/database.g.dart | 13 ---- lib/src/services/get_it_service.dart | 6 +- pubspec.lock | 72 -------------------- pubspec.yaml | 3 - 10 files changed, 1 insertion(+), 206 deletions(-) delete mode 100644 lib/src/database/connection/connection.dart delete mode 100644 lib/src/database/connection/native.dart delete mode 100644 lib/src/database/connection/unsupported.dart delete mode 100644 lib/src/database/connection/web.dart delete mode 100644 lib/src/database/database.dart delete mode 100644 lib/src/database/database.g.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index ed6f38a..aa39b23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ - Bump dependencies - Add get_it -- Add Drift ## 1.8.0 diff --git a/lib/src/database/connection/connection.dart b/lib/src/database/connection/connection.dart deleted file mode 100644 index 827bd5c..0000000 --- a/lib/src/database/connection/connection.dart +++ /dev/null @@ -1,5 +0,0 @@ -// We use a conditional export to expose the right connection factory depending -// on the platform. -export 'unsupported.dart' - if (dart.library.js) 'web.dart' - if (dart.library.ffi) 'native.dart'; diff --git a/lib/src/database/connection/native.dart b/lib/src/database/connection/native.dart deleted file mode 100644 index a37cd4a..0000000 --- a/lib/src/database/connection/native.dart +++ /dev/null @@ -1,40 +0,0 @@ -// ignore_for_file: depend_on_referenced_packages - -import 'dart:io'; - -import 'package:drift/drift.dart'; -import 'package:drift/native.dart'; -import 'package:drift_dev/api/migrations.dart'; -import 'package:flutter/foundation.dart'; -import 'package:path/path.dart' as p; -import 'package:path_provider/path_provider.dart'; - -Future get databaseFile async { - // We use `path_provider` to find a suitable path to store our data in. - final Directory appDir = await getApplicationDocumentsDirectory(); - final String dbPath = p.join(appDir.path, 'todos.db'); - return File(dbPath); -} - -/// Obtains a database connection for running drift in a Dart VM. -DatabaseConnection connect() { - return DatabaseConnection.delayed( - Future(() async { - return NativeDatabase.createBackgroundConnection(await databaseFile); - }), - ); -} - -Future validateDatabaseSchema(final GeneratedDatabase database) async { - // 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) { - await VerifySelf(database).validateDatabaseSchema(); - } -} diff --git a/lib/src/database/connection/unsupported.dart b/lib/src/database/connection/unsupported.dart deleted file mode 100644 index e5bd53c..0000000 --- a/lib/src/database/connection/unsupported.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:drift/drift.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 - -DatabaseConnection connect() { - _unsupported(); -} - -Future validateDatabaseSchema(final GeneratedDatabase database) async { - _unsupported(); -} diff --git a/lib/src/database/connection/web.dart b/lib/src/database/connection/web.dart deleted file mode 100644 index 97da8ec..0000000 --- a/lib/src/database/connection/web.dart +++ /dev/null @@ -1,34 +0,0 @@ -import 'dart:async'; - -import 'package:drift/drift.dart'; -import 'package:drift/wasm.dart'; -import 'package:flutter/foundation.dart'; - -/// Obtains a database connection for running drift on the web. -DatabaseConnection connect() { - return DatabaseConnection.delayed( - Future(() async { - final WasmDatabaseResult db = await WasmDatabase.open( - databaseName: 'drift-app-database', - sqlite3Uri: Uri.parse('/sqlite3.wasm'), - driftWorkerUri: Uri.parse('/drift_worker.js'), - ); - - if (db.missingFeatures.isNotEmpty) { - debugPrint( - 'Using ${db.chosenImplementation} due to unsupported ' - 'browser features: ${db.missingFeatures}', - ); - } - - return db.resolvedExecutor; - }), - ); -} - -Future validateDatabaseSchema(final 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. -} diff --git a/lib/src/database/database.dart b/lib/src/database/database.dart deleted file mode 100644 index 68091c2..0000000 --- a/lib/src/database/database.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:drift/drift.dart'; - -import 'connection/connection.dart' as impl; - -part 'database.g.dart'; - -@DriftDatabase(tables: []) -class AppDatabase extends _$AppDatabase { - AppDatabase() : super(impl.connect()); - - AppDatabase.forTesting(super.connection); - - @override - int get schemaVersion => 1; -} diff --git a/lib/src/database/database.g.dart b/lib/src/database/database.g.dart deleted file mode 100644 index 245f9b3..0000000 --- a/lib/src/database/database.g.dart +++ /dev/null @@ -1,13 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'database.dart'; - -// ignore_for_file: type=lint -abstract class _$AppDatabase extends GeneratedDatabase { - _$AppDatabase(QueryExecutor e) : super(e); - @override - Iterable> get allTables => - allSchemaEntities.whereType>(); - @override - List get allSchemaEntities => []; -} diff --git a/lib/src/services/get_it_service.dart b/lib/src/services/get_it_service.dart index 1093aab..8b4f444 100644 --- a/lib/src/services/get_it_service.dart +++ b/lib/src/services/get_it_service.dart @@ -1,9 +1,5 @@ import 'package:get_it/get_it.dart'; -import '/src/database/database.dart'; - final GetIt getIt = GetIt.instance; -void setupDependencies() { - getIt.registerSingleton(AppDatabase()); -} +void setupDependencies() {} diff --git a/pubspec.lock b/pubspec.lock index c7edded..85ac319 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -17,14 +17,6 @@ packages: url: "https://pub.dev" source: hosted version: "5.13.0" - analyzer_plugin: - dependency: transitive - description: - name: analyzer_plugin - sha256: c1d5f167683de03d5ab6c3b53fc9aeefc5d59476e7810ba7bbddff50c6f4392d - url: "https://pub.dev" - source: hosted - version: "0.11.2" archive: dependency: transitive description: @@ -169,14 +161,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.0" - charcode: - dependency: transitive - description: - name: charcode - sha256: fb98c0f6d12c920a02ee2d998da788bca066ca5f148492b7085ee23372b12306 - url: "https://pub.dev" - source: hosted - version: "1.3.1" checked_yaml: dependency: transitive description: @@ -185,14 +169,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" - cli_util: - dependency: transitive - description: - name: cli_util - sha256: b8db3080e59b2503ca9e7922c3df2072cf13992354d5e944074ffa836fba43b7 - url: "https://pub.dev" - source: hosted - version: "0.4.0" clock: dependency: transitive description: @@ -273,22 +249,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.8" - drift: - dependency: "direct main" - description: - name: drift - sha256: "01e7237766b3404f08489ed0dc531a2fa5f5a42d7fa7787da6cc0a10e8d2632f" - url: "https://pub.dev" - source: hosted - version: "2.10.0" - drift_dev: - dependency: "direct dev" - description: - name: drift_dev - sha256: "407eb1f149332238c567f06cc89b6aaee848de00d9031c76dc372dc16d993bca" - url: "https://pub.dev" - source: hosted - version: "2.10.0" fake_async: dependency: transitive description: @@ -749,14 +709,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.3" - recase: - dependency: transitive - description: - name: recase - sha256: e4eb4ec2dcdee52dcf99cb4ceabaffc631d7424ee55e56f280bc039737f89213 - url: "https://pub.dev" - source: hosted - version: "4.1.0" rxdart: dependency: transitive description: @@ -834,30 +786,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.4.5+1" - sqlite3: - dependency: transitive - description: - name: sqlite3 - sha256: f7511ddd6a2dda8ded9d849f8a925bb6020e0faa59db2443debc18d484e59401 - url: "https://pub.dev" - source: hosted - version: "2.0.0" - sqlite3_flutter_libs: - dependency: "direct main" - description: - name: sqlite3_flutter_libs - sha256: "1e20a88d5c7ae8400e009f38ddbe8b001800a6dffa37832481a86a219bc904c7" - url: "https://pub.dev" - source: hosted - version: "0.5.15" - sqlparser: - dependency: transitive - description: - name: sqlparser - sha256: "9611f46d30a4e8286e54d17a1b5182d132512dc6fc3da90c45ad8ec2828a58b1" - url: "https://pub.dev" - source: hosted - version: "0.30.3" stack_trace: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 32dc447..801fd30 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,8 +21,6 @@ dependencies: # Storage hive: ^2.2.3 hive_flutter: ^1.1.0 - drift: ^2.10.0 - sqlite3_flutter_libs: ^0.5.15 # Internationalization and localization flutter_localizations: @@ -63,7 +61,6 @@ dev_dependencies: freezed: ^2.4.1 hive_generator: ^2.0.0 json_serializable: ^6.7.1 - drift_dev: ^2.10.0 flutter: uses-material-design: true