Skip to content

Commit

Permalink
feat: added drift
Browse files Browse the repository at this point in the history
  • Loading branch information
f7deleon committed Aug 3, 2023
1 parent 809ef4c commit 0c1d82d
Show file tree
Hide file tree
Showing 20 changed files with 509 additions and 364 deletions.
36 changes: 24 additions & 12 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@ PODS:
- Flutter
- flutter_web_browser (0.17.1):
- Flutter
- FMDB (2.7.5):
- FMDB/standard (= 2.7.5)
- FMDB/standard (2.7.5)
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- sqflite (0.0.2):
- sqlite3 (3.38.5):
- sqlite3/common (= 3.38.5)
- sqlite3/common (3.38.5)
- sqlite3/fts5 (3.38.5):
- sqlite3/common
- sqlite3/json1 (3.38.5):
- sqlite3/common
- sqlite3/perf-threadsafe (3.38.5):
- sqlite3/common
- sqlite3/rtree (3.38.5):
- sqlite3/common
- sqlite3_flutter_libs (0.0.1):
- Flutter
- FMDB (>= 2.7.5)
- sqlite3 (~> 3.38.2)
- sqlite3/fts5
- sqlite3/json1
- sqlite3/perf-threadsafe
- sqlite3/rtree

DEPENDENCIES:
- Flutter (from `Flutter`)
Expand All @@ -26,11 +38,11 @@ DEPENDENCIES:
- flutter_web_browser (from `.symlinks/plugins/flutter_web_browser/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
- sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/ios`)

SPEC REPOS:
trunk:
- FMDB
- sqlite3

EXTERNAL SOURCES:
Flutter:
Expand All @@ -45,19 +57,19 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
sqflite:
:path: ".symlinks/plugins/sqflite/ios"
sqlite3_flutter_libs:
:path: ".symlinks/plugins/sqlite3_flutter_libs/ios"

SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be
flutter_web_browser: 7bccaafbb0c5b8862afe7bcd158f15557109f61f
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9
shared_preferences_foundation: 986fc17f3d3251412d18b0265f9c64113a8c2472
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904
sqlite3: 93442daab2ab1825bc9c05faa85814a1996f5b65
sqlite3_flutter_libs: e21c8c90448ce608a0d685e717727c46f37c6695

PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048

COCOAPODS: 1.11.3
COCOAPODS: 1.12.1
1 change: 1 addition & 0 deletions ios/Runner.xcodeproj/build/.last_build_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
be0f9cbaccd7d29ffb981a4ff244b5fd
12 changes: 12 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 21BC3E4201BD6DDEC1196AA9 /* Pods-Runner.debug-prod.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = LHNK868N8C;
PRODUCT_NAME = Runner;
};
name = "Debug-prod";
Expand All @@ -349,6 +350,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = E65075458592F9F001F344C1 /* Pods-Runner.profile-prod.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = LHNK868N8C;
PRODUCT_NAME = Runner;
};
name = "Profile-prod";
Expand All @@ -357,6 +359,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 2B82596BB830AA758A68457E /* Pods-Runner.release-prod.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = LHNK868N8C;
PRODUCT_NAME = Runner;
};
name = "Release-prod";
Expand Down Expand Up @@ -488,6 +491,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = LHNK868N8C;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -762,6 +766,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = LHNK868N8C;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -783,6 +788,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = LHNK868N8C;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -877,6 +883,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = LHNK868N8C;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -972,6 +979,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = LHNK868N8C;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -1064,6 +1072,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = LHNK868N8C;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -1155,6 +1164,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = LHNK868N8C;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -1244,6 +1254,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = LHNK868N8C;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -1333,6 +1344,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = LHNK868N8C;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
4 changes: 0 additions & 4 deletions lib/core/di/app_providers_module.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_template/core/source/common/app_database.dart';
import 'package:get_it/get_it.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_template/core/source/common/local_shared_preferences_storage.dart';
Expand All @@ -20,9 +19,6 @@ class AppProvidersModule {

extension _GetItDiModuleExtensions on GetIt {
void _setupModule() {
registerSingletonAsync(
() => $FloorAppDatabase.databaseBuilder('app_database.db').build(),
);
registerLazySingleton(FlutterSecureStorage.new);
registerSingletonAsync(() => SharedPreferences.getInstance());

Expand Down
2 changes: 2 additions & 0 deletions lib/core/di/di_repository_module.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:drift/native.dart';
import 'package:flutter_template/core/repository/project_repository.dart';
import 'package:flutter_template/core/repository/session_repository.dart';
import 'package:flutter_template/core/source/auth_local_source.dart';
Expand Down Expand Up @@ -35,6 +36,7 @@ extension _GetItDiModuleExtensions on GetIt {
}

void _setupSources() {
registerLazySingleton(() => AppDatabase(NativeDatabase.memory()));
registerLazySingleton(() => AuthLocalSource(get()));
registerLazySingleton(() => AuthRemoteSource(get()));
registerLazySingleton(() => get<AppDatabase>().projectLocalSource);
Expand Down
20 changes: 20 additions & 0 deletions lib/core/model/db/project.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
part of 'package:flutter_template/core/source/common/app_database.dart';

@DataClassName('Project')
class ProjectTable extends Table {
IntColumn get id => integer().autoIncrement()();

TextColumn get name => text()();

TextColumn get description => text()();

TextColumn get url => text()();

@JsonKey('image_url')
TextColumn get imageUrl => text()();

TextColumn get language => text()();

@override
Set<Column> get primaryKey => {id};
}
21 changes: 0 additions & 21 deletions lib/core/model/db/repository_db_entity.dart

This file was deleted.

21 changes: 0 additions & 21 deletions lib/core/model/project.dart

This file was deleted.

38 changes: 0 additions & 38 deletions lib/core/model/serializer/project_serializer.dart

This file was deleted.

8 changes: 3 additions & 5 deletions lib/core/repository/project_repository.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:flutter_template/core/model/db/repository_db_entity.dart';
import 'package:flutter_template/core/model/project.dart';
import 'package:flutter_template/core/model/serializer/project_serializer.dart';
import 'package:flutter_template/core/source/common/app_database.dart';
import 'package:flutter_template/core/source/project_local_source.dart';
import 'package:flutter_template/core/source/project_remote_source.dart';
import 'package:stock/stock.dart';
Expand All @@ -19,10 +17,10 @@ class ProjectRepository {
fetcher: Fetcher.ofFuture(
(_) => _projectRemoteSource.getProjects(),
),
sourceOfTruth: SourceOfTruth<dynamic, List<ProjectDbEntity>>(
sourceOfTruth: SourceOfTruth<dynamic, List<Project>>(
reader: (_) => _projectLocalSource.getProjects(),
writer: (_, value) => _projectLocalSource.replaceProjects(value),
).mapToUsingMapper(ProjectListStockTypeMapper()),
),
);

Stream<List<Project>?> getProjects() => _store
Expand Down
3 changes: 2 additions & 1 deletion lib/core/repository/session_repository.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:drift/drift.dart';
import 'package:flutter_template/core/model/authentication_status.dart';
import 'package:flutter_template/core/model/user.dart';
import 'package:flutter_template/core/source/auth_local_source.dart';
Expand Down Expand Up @@ -36,7 +37,7 @@ class SessionRepository {
}

Future<void> logOut() async {
await _appDataBase.clearAllTables();
await _appDataBase.projectTable.deleteAll();
await _authLocalSource.saveUserToken(null);
await _authLocalSource.saveUserInfo(null);
}
Expand Down
28 changes: 16 additions & 12 deletions lib/core/source/common/app_database.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
// database.dart

import 'dart:async';

import 'package:floor/floor.dart';
import 'package:flutter_template/core/model/db/repository_db_entity.dart';
import 'package:drift/drift.dart';
import 'package:flutter_template/core/source/project_local_source.dart';
import 'package:sqflite/sqflite.dart' as sqflite;

part 'app_database.g.dart';

@Database(version: 1, entities: [ProjectDbEntity])
abstract class AppDatabase extends FloorDatabase {
ProjectLocalSource get projectLocalSource;
part 'package:flutter_template/core/model/db/project.dart';

@DriftDatabase(
tables: [
ProjectTable,
],
daos: [ProjectLocalSource],
)
class AppDatabase extends _$AppDatabase {
AppDatabase(QueryExecutor e) : super(e);

Future<void> clearAllTables() async {
await database.delete('projects');
}
@override
int get schemaVersion => 1;
@override
// TODO: implement migration
MigrationStrategy get migration => super.migration;
}
Loading

0 comments on commit 0c1d82d

Please sign in to comment.