diff --git a/.github/actions/flutter-common/action.yml b/.github/actions/flutter-common/action.yml index 800e70ab6..5e52b587b 100644 --- a/.github/actions/flutter-common/action.yml +++ b/.github/actions/flutter-common/action.yml @@ -9,7 +9,7 @@ runs: uses: subosito/flutter-action@v2 with: channel: stable - flutter-version: 3.41.9 + flutter-version: 3.44.0 cache: true - name: Install Flutter dependencies diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 435efe115..a1e51813e 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -61,7 +61,7 @@ jobs: - name: Build application for linux run: | sudo apt update - sudo apt install -y pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev --no-install-recommends + sudo apt install -y pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev libsecret-1-dev libjsoncpp-dev --no-install-recommends flutter build linux --release tar -zcvf linux-${{ matrix.platform }}.tar.gz build/linux/${{ matrix.platform }}/release/bundle - uses: actions/upload-artifact@v7 diff --git a/.github/workflows/screenshots.yml b/.github/workflows/screenshots.yml index d28333fcc..f26dc11ce 100644 --- a/.github/workflows/screenshots.yml +++ b/.github/workflows/screenshots.yml @@ -20,12 +20,6 @@ jobs: - name: Common flutter setup uses: ./.github/actions/flutter-common - - name: Install CocoaPods - run: | - cd ios - pod install || true - cd .. - - name: Boot iOS simulator id: boot run: | diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 95065c030..6bdaaffc2 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -49,6 +49,15 @@ + + + + + + + + diff --git a/build.yaml b/build.yaml new file mode 100644 index 000000000..4f5dac214 --- /dev/null +++ b/build.yaml @@ -0,0 +1,6 @@ +targets: + $default: + builders: + drift_dev: + options: + store_date_time_values_as_text: true \ No newline at end of file diff --git a/devtools_options.yaml b/devtools_options.yaml index 75bd2b677..02a606107 100644 --- a/devtools_options.yaml +++ b/devtools_options.yaml @@ -1,3 +1,4 @@ extensions: - drift: true - - provider: true \ No newline at end of file + - provider: true + - shared_preferences: true \ No newline at end of file diff --git a/flatpak/de.wger.flutter.desktop b/flatpak/de.wger.flutter.desktop index 8aaa5559a..57ac3f9f0 100755 --- a/flatpak/de.wger.flutter.desktop +++ b/flatpak/de.wger.flutter.desktop @@ -8,7 +8,8 @@ Comment=Fitness/workout, nutrition and weight tracker # HealthFitness;Exercise;Nutrition Categories=Education;Utility;Sports; Icon=de.wger.flutter -Exec=wger +Exec=wger %u +MimeType=x-scheme-handler/wger; StartupWMClass=wger X-Purism-FormFactor=Workstation;Mobile; X-KDE-FormFactors=desktop;tablet;handset;mediacenter; diff --git a/flatpak/de.wger.flutter.service b/flatpak/de.wger.flutter.service new file mode 100644 index 000000000..dbf58074e --- /dev/null +++ b/flatpak/de.wger.flutter.service @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=de.wger.flutter +Exec=/app/bin/wger --gapplication-service diff --git a/integration_test/make_screenshots_test.dart b/integration_test/make_screenshots_test.dart index 8c13c1df5..80e90f1d5 100644 --- a/integration_test/make_screenshots_test.dart +++ b/integration_test/make_screenshots_test.dart @@ -44,8 +44,7 @@ enum DeviceType { androidWear('wearScreenshots'), iOSPhoneBig('iPhone 6.9', isAndroid: false), - iOSPhoneSmall('iPhone 6.7', isAndroid: false) - ; + iOSPhoneSmall('iPhone 6.7', isAndroid: false); final String folderName; final bool isAndroid; diff --git a/integration_test/screenshots_01_dashboard.dart b/integration_test/screenshots_01_dashboard.dart index 5c9b033b0..5ca4139b1 100644 --- a/integration_test/screenshots_01_dashboard.dart +++ b/integration_test/screenshots_01_dashboard.dart @@ -17,131 +17,112 @@ */ import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart' as riverpod; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:mockito/mockito.dart'; -import 'package:provider/provider.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; -import 'package:wger/models/workouts/session.dart'; -import 'package:wger/providers/auth.dart'; -import 'package:wger/providers/body_weight.dart'; -import 'package:wger/providers/exercises.dart'; -import 'package:wger/providers/gallery.dart'; -import 'package:wger/providers/measurement.dart'; -import 'package:wger/providers/nutrition.dart'; -import 'package:wger/providers/routines.dart'; -import 'package:wger/providers/user.dart'; +import 'package:wger/models/measurements/measurement_category.dart'; +import 'package:wger/providers/auth_notifier.dart'; +import 'package:wger/providers/auth_state.dart'; +import 'package:wger/providers/body_weight_repository.dart'; +import 'package:wger/providers/gallery_repository.dart'; +import 'package:wger/providers/ingredient_repository.dart'; +import 'package:wger/providers/measurement_repository.dart'; +import 'package:wger/providers/nutrition_notifier.dart'; +import 'package:wger/providers/nutrition_repository.dart'; +import 'package:wger/providers/routines_notifier.dart'; +import 'package:wger/providers/user_profile_repository.dart'; import 'package:wger/screens/home_tabs_screen.dart'; import 'package:wger/theme/theme.dart'; -import '../test/exercises/contribute_exercise_test.mocks.dart'; import '../test/gallery/gallery_form_test.mocks.dart'; import '../test/measurements/measurement_categories_screen_test.mocks.dart'; import '../test/nutrition/nutritional_plan_screen_test.mocks.dart'; -import '../test/routine/weight_unit_form_widget_test.mocks.dart'; import '../test/weight/weight_screen_test.mocks.dart' as weight; import '../test_data/body_weight.dart'; import '../test_data/exercises.dart'; +import '../test_data/gallery.dart'; import '../test_data/measurements.dart'; import '../test_data/nutritional_plans.dart'; import '../test_data/profile.dart'; import '../test_data/routines.dart'; -Widget createDashboardScreen({Locale? locale}) { - locale ??= const Locale('en'); +class _FakeAuthNotifier extends AuthNotifier { + _FakeAuthNotifier(this._state); - final mockGalleryProvider = MockGalleryProvider(); + final AuthState _state; - final mockExercisesProvider = MockExercisesProvider(); + @override + Future build() async => _state; +} - final mockAuthProvider = MockAuthProvider(); - when(mockAuthProvider.setServerVersion()).thenAnswer((_) async {}); - when(mockAuthProvider.dataInit).thenReturn(true); +Widget createDashboardScreen({Locale? locale}) { + locale ??= const Locale('en'); - final mockWorkoutProvider = MockRoutinesProvider(); - when(mockWorkoutProvider.items).thenReturn([getTestRoutine(exercises: getScreenshotExercises())]); - when( - mockWorkoutProvider.currentRoutine, - ).thenReturn(getTestRoutine(exercises: getScreenshotExercises())); + final mockGalleryRepo = MockGalleryRepository(); + when(mockGalleryRepo.watchAllDrift()).thenAnswer((_) => Stream.value(getTestImages())); - when(mockWorkoutProvider.fetchSessionData()).thenAnswer( - (a) => Future.value([ - WorkoutSession( - routineId: 1, - date: DateTime.now().add(const Duration(days: -1)), - timeStart: const TimeOfDay(hour: 17, minute: 34), - timeEnd: const TimeOfDay(hour: 19, minute: 3), - impression: 3, - ), - ]), - ); + final mockNutritionRepo = weight.MockNutritionRepository(); + final mockIngredientRepo = weight.MockIngredientRepository(); + when(mockIngredientRepo.getById(any)).thenAnswer((_) async => null); - final mockNutritionProvider = weight.MockNutritionPlansProvider(); + final mockBodyWeightRepository = MockBodyWeightRepository(); + when( + mockBodyWeightRepository.watchAllDrift(), + ).thenAnswer((_) => Stream.value(getWeightEntries())); + final mockMeasurementRepo = MockMeasurementRepository(); when( - mockNutritionProvider.currentPlan, - ).thenAnswer((realInvocation) => getNutritionalPlanScreenshot()); - when(mockNutritionProvider.items).thenReturn([getNutritionalPlanScreenshot()]); + mockMeasurementRepo.watchAll(), + ).thenAnswer((_) => Stream>.value(getMeasurementCategories())); - final mockWeightProvider = weight.MockBodyWeightProvider(); - when(mockWeightProvider.items).thenReturn(getScreenshotWeightEntries()); + final mockUserProfileRepo = weight.MockUserProfileRepository(); + when( + mockUserProfileRepo.watchDrift(), + ).thenAnswer((_) => Stream.value(tUserProfile1)); - final mockMeasurementProvider = MockMeasurementProvider(); - when(mockMeasurementProvider.categories).thenReturn(getMeasurementCategories()); + const loggedInAuth = AuthState( + status: AuthStatus.loggedIn, + token: 'test-token', + serverUrl: 'http://localhost', + ); + final container = ProviderContainer.test( + overrides: [ + bodyWeightRepositoryProvider.overrideWithValue(mockBodyWeightRepository), + measurementRepositoryProvider.overrideWithValue(mockMeasurementRepo), + authProvider.overrideWith(() => _FakeAuthNotifier(loggedInAuth)), + userProfileRepositoryProvider.overrideWithValue(mockUserProfileRepo), + nutritionRepositoryProvider.overrideWithValue(mockNutritionRepo), + ingredientRepositoryProvider.overrideWithValue(mockIngredientRepo), + galleryRepositoryProvider.overrideWithValue(mockGalleryRepo), + ], + ); + container.read(routinesRiverpodProvider.notifier).state = AsyncData( + RoutinesState( + routines: [getTestRoutine(exercises: getScreenshotExercises())], + ), + ); - final mockUserProvider = MockUserProvider(); - when(mockUserProvider.profile).thenReturn(tProfile1); - when(mockUserProvider.dashboardWidgets).thenReturn([ - DashboardWidget.routines, - DashboardWidget.weight, - DashboardWidget.measurements, - DashboardWidget.calendar, - DashboardWidget.nutrition, - DashboardWidget.trophies, - ]); + // Seed the nutrition notifier with the screenshot plan so the dashboard can + // show it without going through the server. + container.read(nutritionProvider.notifier).state = AsyncData( + NutritionState(plans: [getNutritionalPlanScreenshot()]), + ); - return riverpod.ProviderScope( - child: MediaQuery( - data: MediaQueryData.fromView(WidgetsBinding.instance.platformDispatcher.views.first) - .copyWith( - padding: EdgeInsets.zero, - viewPadding: EdgeInsets.zero, - viewInsets: EdgeInsets.zero, - ), - child: MultiProvider( - providers: [ - ChangeNotifierProvider( - create: (context) => mockGalleryProvider, - ), - ChangeNotifierProvider( - create: (context) => mockExercisesProvider, - ), - ChangeNotifierProvider( - create: (context) => mockAuthProvider, - ), - ChangeNotifierProvider( - create: (context) => mockUserProvider, - ), - ChangeNotifierProvider( - create: (context) => mockWorkoutProvider, - ), - ChangeNotifierProvider( - create: (context) => mockNutritionProvider, - ), - ChangeNotifierProvider( - create: (context) => mockWeightProvider, - ), - ChangeNotifierProvider( - create: (context) => mockMeasurementProvider, - ), - ], - child: MaterialApp( - locale: locale, - debugShowCheckedModeBanner: false, - localizationsDelegates: AppLocalizations.localizationsDelegates, - supportedLocales: AppLocalizations.supportedLocales, - theme: wgerLightTheme, - home: HomeTabsScreen(), - ), + return MediaQuery( + data: MediaQueryData.fromView(WidgetsBinding.instance.platformDispatcher.views.first).copyWith( + padding: EdgeInsets.zero, + viewPadding: EdgeInsets.zero, + viewInsets: EdgeInsets.zero, + ), + child: UncontrolledProviderScope( + container: container, + child: MaterialApp( + locale: locale, + debugShowCheckedModeBanner: false, + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + theme: wgerLightTheme, + home: HomeTabsScreen(), ), ), ); diff --git a/integration_test/screenshots_02_workout.dart b/integration_test/screenshots_02_workout.dart index 3900dbef9..8cee46765 100644 --- a/integration_test/screenshots_02_workout.dart +++ b/integration_test/screenshots_02_workout.dart @@ -17,14 +17,12 @@ */ import 'package:flutter/material.dart'; -import 'package:mockito/mockito.dart'; -import 'package:provider/provider.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart' as riverpod; import 'package:wger/l10n/generated/app_localizations.dart'; -import 'package:wger/providers/routines.dart'; +import 'package:wger/providers/routines_notifier.dart'; import 'package:wger/screens/routine_screen.dart'; import 'package:wger/theme/theme.dart'; -import '../test/routine/routine_form_test.mocks.dart'; import '../test_data/exercises.dart'; import '../test_data/routines.dart'; @@ -32,9 +30,13 @@ Widget createWorkoutDetailScreen({Locale? locale}) { locale ??= const Locale('en'); final key = GlobalKey(); - final mockRoutinesProvider = MockRoutinesProvider(); final routine = getTestRoutine(exercises: getScreenshotExercises()); - when(mockRoutinesProvider.findById(1)).thenReturn(routine); + final container = riverpod.ProviderContainer.test(); + container.read(routinesRiverpodProvider.notifier).state = riverpod.AsyncData( + RoutinesState( + routines: [getTestRoutine(exercises: getScreenshotExercises())], + ), + ); return MediaQuery( data: MediaQueryData.fromView(WidgetsBinding.instance.platformDispatcher.views.first).copyWith( @@ -42,12 +44,8 @@ Widget createWorkoutDetailScreen({Locale? locale}) { viewPadding: EdgeInsets.zero, viewInsets: EdgeInsets.zero, ), - child: MultiProvider( - providers: [ - ChangeNotifierProvider( - create: (context) => mockRoutinesProvider, - ), - ], + child: riverpod.UncontrolledProviderScope( + container: container, child: MaterialApp( locale: locale, debugShowCheckedModeBanner: false, diff --git a/integration_test/screenshots_03_gym_mode.dart b/integration_test/screenshots_03_gym_mode.dart index fbc405eed..6f1ba7028 100644 --- a/integration_test/screenshots_03_gym_mode.dart +++ b/integration_test/screenshots_03_gym_mode.dart @@ -19,35 +19,45 @@ import 'package:clock/clock.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart' as riverpod; -import 'package:mockito/mockito.dart'; -import 'package:provider/provider.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; -import 'package:wger/providers/exercises.dart'; +import 'package:wger/models/workouts/routine.dart'; +import 'package:wger/providers/exercise_filter_state.dart'; +import 'package:wger/providers/exercise_filters_notifier.dart'; import 'package:wger/providers/gym_state.dart'; -import 'package:wger/providers/routines.dart'; -import 'package:wger/providers/wger_base_riverpod.dart'; +import 'package:wger/providers/routines_notifier.dart'; import 'package:wger/screens/gym_mode.dart'; import 'package:wger/screens/routine_screen.dart'; import 'package:wger/theme/theme.dart'; import 'package:wger/widgets/routines/gym_mode/summary.dart'; -import '../test/routine/gym_mode/gym_mode_test.mocks.dart'; import '../test_data/exercises.dart'; import '../test_data/routines.dart'; +class _StubRoutinesRiverpod extends RoutinesRiverpod { + _StubRoutinesRiverpod(this._routines); + final List _routines; + + @override + Stream build() => Stream.value(RoutinesState(routines: _routines)); +} + Widget createGymModeScreen({Locale? locale}) { locale ??= const Locale('en'); final key = GlobalKey(); - final exercises = getTestExercises(); - final routine = getTestRoutine(exercises: getScreenshotExercises()); - final mockRoutinesProvider = MockRoutinesProvider(); - final mockExerciseProvider = MockExercisesProvider(); - - when(mockRoutinesProvider.fetchAndSetRoutineFull(1)).thenAnswer((_) async => routine); - when(mockRoutinesProvider.findById(1)).thenAnswer((_) => routine); - when(mockExerciseProvider.findExerciseById(1)).thenReturn(exercises[0]); // bench press - when(mockExerciseProvider.findExerciseById(6)).thenReturn(exercises[5]); // side raises + final routine = getTestRoutine(exercises: getScreenshotExercises()); + final container = riverpod.ProviderContainer.test( + overrides: [ + exerciseListFiltersProvider.overrideWithValue( + ExerciseFilterState(exercises: getTestExercises()), + ), + ], + ); + container.read(routinesRiverpodProvider.notifier).state = riverpod.AsyncData( + RoutinesState( + routines: [getTestRoutine(exercises: getScreenshotExercises())], + ), + ); return MediaQuery( data: MediaQueryData.fromView(WidgetsBinding.instance.platformDispatcher.views.first).copyWith( @@ -55,41 +65,29 @@ Widget createGymModeScreen({Locale? locale}) { viewPadding: EdgeInsets.zero, viewInsets: EdgeInsets.zero, ), - child: riverpod.ProviderScope( - overrides: [ - wgerBaseProvider.overrideWithValue(MockWgerBaseProvider()), - ], - child: MultiProvider( - providers: [ - ChangeNotifierProvider( - create: (context) => mockRoutinesProvider, - ), - ChangeNotifierProvider( - create: (context) => mockExerciseProvider, - ), - ], - child: MaterialApp( - locale: locale, - debugShowCheckedModeBanner: false, - localizationsDelegates: AppLocalizations.localizationsDelegates, - supportedLocales: AppLocalizations.supportedLocales, - navigatorKey: key, - theme: wgerLightTheme, - home: TextButton( - onPressed: () => key.currentState!.push( - MaterialPageRoute( - settings: RouteSettings( - arguments: GymModeArguments(routine.id!, routine.days.first.id!, 1), - ), - builder: (_) => const GymModeScreen(), + child: riverpod.UncontrolledProviderScope( + container: container, + child: MaterialApp( + locale: locale, + debugShowCheckedModeBanner: false, + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + navigatorKey: key, + theme: wgerLightTheme, + home: TextButton( + onPressed: () => key.currentState!.push( + MaterialPageRoute( + settings: RouteSettings( + arguments: GymModeArguments(routine.id!, routine.days.first.id!, 1), ), + builder: (_) => const GymModeScreen(), ), - child: const SizedBox(), ), - routes: { - RoutineScreen.routeName: (ctx) => const RoutineScreen(), - }, + child: const SizedBox(), ), + routes: { + RoutineScreen.routeName: (ctx) => const RoutineScreen(), + }, ), ), ); @@ -100,18 +98,11 @@ Widget createGymModeResultsScreen({String locale = 'en'}) { final key = GlobalKey(); final routine = getTestRoutine(exercises: getScreenshotExercises()); - routine.sessions.first.session.date = clock.now(); - - final mockRoutinesProvider = MockRoutinesProvider(); - final mockExerciseProvider = MockExercisesProvider(); - - when(mockRoutinesProvider.fetchAndSetRoutineFull(1)).thenAnswer((_) async => routine); - when(mockRoutinesProvider.findById(1)).thenAnswer((_) => routine); + routine.sessions.first.date = clock.now(); return riverpod.UncontrolledProviderScope( container: riverpod.ProviderContainer.test( overrides: [ - wgerBaseProvider.overrideWithValue(MockWgerBaseProvider()), gymStateProvider.overrideWithValue( GymModeState( routine: routine, @@ -121,31 +112,25 @@ Widget createGymModeResultsScreen({String locale = 'en'}) { showTimerPages: true, ), ), - ], - ), - child: MultiProvider( - providers: [ - ChangeNotifierProvider( - create: (context) => mockRoutinesProvider, - ), - ChangeNotifierProvider( - create: (context) => mockExerciseProvider, + routinesRiverpodProvider.overrideWith( + () => _StubRoutinesRiverpod([routine]), ), ], - child: MaterialApp( - locale: Locale(locale), - debugShowCheckedModeBanner: false, - localizationsDelegates: AppLocalizations.localizationsDelegates, - supportedLocales: AppLocalizations.supportedLocales, - navigatorKey: key, - theme: wgerLightTheme, - home: Scaffold( - body: PageView( - controller: controller, - children: [ - WorkoutSummary(controller), - ], - ), + ), + + child: MaterialApp( + locale: Locale(locale), + debugShowCheckedModeBanner: false, + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + navigatorKey: key, + theme: wgerLightTheme, + home: Scaffold( + body: PageView( + controller: controller, + children: [ + WorkoutSummary(controller), + ], ), ), ), diff --git a/integration_test/screenshots_04_measurements.dart b/integration_test/screenshots_04_measurements.dart index c42b5af0b..423648f72 100644 --- a/integration_test/screenshots_04_measurements.dart +++ b/integration_test/screenshots_04_measurements.dart @@ -17,10 +17,11 @@ */ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:mockito/mockito.dart'; -import 'package:provider/provider.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; -import 'package:wger/providers/measurement.dart'; +import 'package:wger/models/measurements/measurement_category.dart'; +import 'package:wger/providers/measurement_repository.dart'; import 'package:wger/screens/measurement_categories_screen.dart'; import 'package:wger/theme/theme.dart'; @@ -30,8 +31,16 @@ import '../test_data/measurements.dart'; Widget createMeasurementScreen({Locale? locale}) { locale ??= const Locale('en'); - final mockMeasurementProvider = MockMeasurementProvider(); - when(mockMeasurementProvider.categories).thenReturn(getMeasurementCategories()); + final mockMeasurementRepo = MockMeasurementRepository(); + when( + mockMeasurementRepo.watchAll(), + ).thenAnswer((_) => Stream>.value(getMeasurementCategories())); + + final container = ProviderContainer.test( + overrides: [ + measurementRepositoryProvider.overrideWithValue(mockMeasurementRepo), + ], + ); return MediaQuery( data: MediaQueryData.fromView(WidgetsBinding.instance.platformDispatcher.views.first).copyWith( @@ -39,12 +48,8 @@ Widget createMeasurementScreen({Locale? locale}) { viewPadding: EdgeInsets.zero, viewInsets: EdgeInsets.zero, ), - child: MultiProvider( - providers: [ - ChangeNotifierProvider( - create: (context) => mockMeasurementProvider, - ), - ], + child: UncontrolledProviderScope( + container: container, child: MaterialApp( locale: locale, debugShowCheckedModeBanner: false, diff --git a/integration_test/screenshots_05_nutritional_plan.dart b/integration_test/screenshots_05_nutritional_plan.dart index df5c67285..a0cbd5212 100644 --- a/integration_test/screenshots_05_nutritional_plan.dart +++ b/integration_test/screenshots_05_nutritional_plan.dart @@ -16,43 +16,46 @@ * along with this program. If not, see . */ -import 'package:drift/native.dart'; import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; -import 'package:wger/database/ingredients/ingredients_database.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:mockito/mockito.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; -import 'package:wger/providers/body_weight.dart'; -import 'package:wger/providers/nutrition.dart'; +import 'package:wger/providers/body_weight_repository.dart'; +import 'package:wger/providers/ingredient_repository.dart'; +import 'package:wger/providers/nutrition_repository.dart'; import 'package:wger/screens/nutritional_plan_screen.dart'; import 'package:wger/theme/theme.dart'; -import '../test/user/provider_test.mocks.dart'; +import '../test/nutrition/nutrition_provider_test.mocks.dart'; +import '../test/weight/weight_provider_test.mocks.dart'; +import '../test_data/body_weight.dart'; import '../test_data/nutritional_plans.dart'; Widget createNutritionalPlanScreen({Locale? locale}) { locale ??= const Locale('en'); - final mockBaseProvider = MockWgerBaseProvider(); final key = GlobalKey(); + final mockNutritionRepo = MockNutritionRepository(); + final mockIngredientRepo = MockIngredientRepository(); + when(mockIngredientRepo.getById(any)).thenAnswer((_) async => null); + + final mockBodyWeightRepository = MockBodyWeightRepository(); + when( + mockBodyWeightRepository.watchAllDrift(), + ).thenAnswer((_) => Stream.value(getWeightEntries())); + return MediaQuery( data: MediaQueryData.fromView(WidgetsBinding.instance.platformDispatcher.views.first).copyWith( padding: EdgeInsets.zero, viewPadding: EdgeInsets.zero, viewInsets: EdgeInsets.zero, ), - child: MultiProvider( - providers: [ - ChangeNotifierProvider( - create: (context) => NutritionPlansProvider( - mockBaseProvider, - [], - database: IngredientDatabase.inMemory(NativeDatabase.memory()), - ), - ), - ChangeNotifierProvider( - create: (context) => BodyWeightProvider(mockBaseProvider), - ), + child: ProviderScope( + overrides: [ + bodyWeightRepositoryProvider.overrideWithValue(mockBodyWeightRepository), + nutritionRepositoryProvider.overrideWithValue(mockNutritionRepo), + ingredientRepositoryProvider.overrideWithValue(mockIngredientRepo), ], child: MaterialApp( locale: locale, diff --git a/integration_test/screenshots_06_weight.dart b/integration_test/screenshots_06_weight.dart index c58c0e812..384f69e50 100644 --- a/integration_test/screenshots_06_weight.dart +++ b/integration_test/screenshots_06_weight.dart @@ -17,17 +17,18 @@ */ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:mockito/mockito.dart'; -import 'package:provider/provider.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; -import 'package:wger/providers/body_weight.dart'; -import 'package:wger/providers/nutrition.dart'; -import 'package:wger/providers/user.dart'; +import 'package:wger/providers/body_weight_repository.dart'; +import 'package:wger/providers/ingredient_repository.dart'; +import 'package:wger/providers/nutrition_notifier.dart'; +import 'package:wger/providers/nutrition_repository.dart'; +import 'package:wger/providers/user_profile_repository.dart'; import 'package:wger/screens/form_screen.dart'; import 'package:wger/screens/weight_screen.dart'; import 'package:wger/theme/theme.dart'; -import '../test/utils.dart'; import '../test/weight/weight_screen_test.mocks.dart'; import '../test_data/body_weight.dart'; import '../test_data/nutritional_plans.dart'; @@ -35,15 +36,32 @@ import '../test_data/profile.dart'; Widget createWeightScreen({Locale? locale}) { locale ??= const Locale('en'); - final weightProvider = BodyWeightProvider(mockBaseProvider); - weightProvider.items = getScreenshotWeightEntries(); + final mockBodyWeightRepository = MockBodyWeightRepository(); + when( + mockBodyWeightRepository.watchAllDrift(), + ).thenAnswer((_) => Stream.value(getWeightEntries())); - final mockUserProvider = MockUserProvider(); - when(mockUserProvider.profile).thenReturn(tProfile1); + final mockUserProfileRepository = MockUserProfileRepository(); + when( + mockUserProfileRepository.watchDrift(), + ).thenAnswer((_) => Stream.value(tUserProfile1)); - final mockNutritionPlansProvider = MockNutritionPlansProvider(); - when(mockNutritionPlansProvider.currentPlan).thenReturn(null); - when(mockNutritionPlansProvider.items).thenReturn([getNutritionalPlan()]); + final mockNutritionRepo = MockNutritionRepository(); + final mockIngredientRepo = MockIngredientRepository(); + when(mockIngredientRepo.getById(any)).thenAnswer((_) async => null); + + final container = ProviderContainer( + overrides: [ + bodyWeightRepositoryProvider.overrideWithValue(mockBodyWeightRepository), + userProfileRepositoryProvider.overrideWithValue(mockUserProfileRepository), + nutritionRepositoryProvider.overrideWithValue(mockNutritionRepo), + ingredientRepositoryProvider.overrideWithValue(mockIngredientRepo), + ], + ); + // Seed the nutrition notifier with a plan so the weight overview can show it. + container.read(nutritionProvider.notifier).state = AsyncData( + NutritionState(plans: [getNutritionalPlan()]), + ); return MediaQuery( data: MediaQueryData.fromView(WidgetsBinding.instance.platformDispatcher.views.first).copyWith( @@ -51,18 +69,8 @@ Widget createWeightScreen({Locale? locale}) { viewPadding: EdgeInsets.zero, viewInsets: EdgeInsets.zero, ), - child: MultiProvider( - providers: [ - ChangeNotifierProvider( - create: (context) => mockUserProvider, - ), - ChangeNotifierProvider( - create: (context) => weightProvider, - ), - ChangeNotifierProvider( - create: (context) => mockNutritionPlansProvider, - ), - ], + child: UncontrolledProviderScope( + container: container, child: MaterialApp( locale: locale, debugShowCheckedModeBanner: false, diff --git a/ios/.gitignore b/ios/.gitignore index e96ef602b..3b89c9c4f 100644 --- a/ios/.gitignore +++ b/ios/.gitignore @@ -10,7 +10,10 @@ **/DerivedData/ Icon? **/Pods/ +/Podfile +/Podfile.lock **/.symlinks/ +**/Flutter/ephemeral/ profile xcuserdata **/.generated/ diff --git a/ios/Flutter/Debug.xcconfig b/ios/Flutter/Debug.xcconfig index e8efba114..592ceee85 100644 --- a/ios/Flutter/Debug.xcconfig +++ b/ios/Flutter/Debug.xcconfig @@ -1,2 +1 @@ -#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/ios/Flutter/Release.xcconfig b/ios/Flutter/Release.xcconfig index 399e9340e..592ceee85 100644 --- a/ios/Flutter/Release.xcconfig +++ b/ios/Flutter/Release.xcconfig @@ -1,2 +1 @@ -#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/ios/Podfile b/ios/Podfile deleted file mode 100644 index 974aea706..000000000 --- a/ios/Podfile +++ /dev/null @@ -1,45 +0,0 @@ -# Uncomment this line to define a global platform for your project -platform :ios, '17.0' - -# CocoaPods analytics sends network stats synchronously affecting flutter build latency. -ENV['COCOAPODS_DISABLE_STATS'] = 'true' - -project 'Runner', { - 'Debug' => :debug, - 'Profile' => :release, - 'Release' => :release, -} - -def flutter_root - generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) - unless File.exist?(generated_xcode_build_settings_path) - raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" - end - - File.foreach(generated_xcode_build_settings_path) do |line| - matches = line.match(/FLUTTER_ROOT\=(.*)/) - return matches[1].strip if matches - end - raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" -end - -require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) - -flutter_ios_podfile_setup - -target 'Runner' do - use_frameworks! - use_modular_headers! - - flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) -end - -post_install do |installer| - installer.pods_project.targets.each do |target| - flutter_additional_ios_build_settings(target) - target.build_configurations.each do |config| - config.build_settings['ENABLE_BITCODE'] = 'NO' - config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0' - end - end -end diff --git a/ios/Podfile.lock b/ios/Podfile.lock deleted file mode 100644 index 21e5c267e..000000000 --- a/ios/Podfile.lock +++ /dev/null @@ -1,112 +0,0 @@ -PODS: - - camera_avfoundation (0.0.1): - - Flutter - - Flutter (1.0.0) - - flutter_native_splash (2.4.3): - - Flutter - - flutter_zxing (0.0.1): - - Flutter - - image_picker_ios (0.0.1): - - Flutter - - integration_test (0.0.1): - - Flutter - - package_info_plus (0.4.5): - - Flutter - - rive_common (0.0.1): - - Flutter - - shared_preferences_foundation (0.0.1): - - Flutter - - FlutterMacOS - - sqlite3 (3.52.0): - - sqlite3/common (= 3.52.0) - - sqlite3/common (3.52.0) - - sqlite3/dbstatvtab (3.52.0): - - sqlite3/common - - sqlite3/fts5 (3.52.0): - - sqlite3/common - - sqlite3/math (3.52.0): - - sqlite3/common - - sqlite3/perf-threadsafe (3.52.0): - - sqlite3/common - - sqlite3/rtree (3.52.0): - - sqlite3/common - - sqlite3/session (3.52.0): - - sqlite3/common - - sqlite3_flutter_libs (0.0.1): - - Flutter - - FlutterMacOS - - sqlite3 (~> 3.52.0) - - sqlite3/dbstatvtab - - sqlite3/fts5 - - sqlite3/math - - sqlite3/perf-threadsafe - - sqlite3/rtree - - sqlite3/session - - url_launcher_ios (0.0.1): - - Flutter - - video_player_avfoundation (0.0.1): - - Flutter - - FlutterMacOS - -DEPENDENCIES: - - camera_avfoundation (from `.symlinks/plugins/camera_avfoundation/ios`) - - Flutter (from `Flutter`) - - flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`) - - flutter_zxing (from `.symlinks/plugins/flutter_zxing/ios`) - - image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`) - - integration_test (from `.symlinks/plugins/integration_test/ios`) - - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - - rive_common (from `.symlinks/plugins/rive_common/ios`) - - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) - - sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/darwin`) - - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) - - video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/darwin`) - -SPEC REPOS: - trunk: - - sqlite3 - -EXTERNAL SOURCES: - camera_avfoundation: - :path: ".symlinks/plugins/camera_avfoundation/ios" - Flutter: - :path: Flutter - flutter_native_splash: - :path: ".symlinks/plugins/flutter_native_splash/ios" - flutter_zxing: - :path: ".symlinks/plugins/flutter_zxing/ios" - image_picker_ios: - :path: ".symlinks/plugins/image_picker_ios/ios" - integration_test: - :path: ".symlinks/plugins/integration_test/ios" - package_info_plus: - :path: ".symlinks/plugins/package_info_plus/ios" - rive_common: - :path: ".symlinks/plugins/rive_common/ios" - shared_preferences_foundation: - :path: ".symlinks/plugins/shared_preferences_foundation/darwin" - sqlite3_flutter_libs: - :path: ".symlinks/plugins/sqlite3_flutter_libs/darwin" - url_launcher_ios: - :path: ".symlinks/plugins/url_launcher_ios/ios" - video_player_avfoundation: - :path: ".symlinks/plugins/video_player_avfoundation/darwin" - -SPEC CHECKSUMS: - camera_avfoundation: 968a9a5323c79a99c166ad9d7866bfd2047b5a9b - Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467 - flutter_native_splash: c32d145d68aeda5502d5f543ee38c192065986cf - flutter_zxing: fe1338b6d79b8a455d209a28381e336b6cfb4161 - image_picker_ios: e0ece4aa2a75771a7de3fa735d26d90817041326 - integration_test: 4a889634ef21a45d28d50d622cf412dc6d9f586e - package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499 - rive_common: dd421daaf9ae69f0125aa761dd96abd278399952 - shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb - sqlite3: a51c07cf16e023d6c48abd5e5791a61a47354921 - sqlite3_flutter_libs: b3e120efe9a82017e5552a620f696589ed4f62ab - url_launcher_ios: 7a95fa5b60cc718a708b8f2966718e93db0cef1b - video_player_avfoundation: dd410b52df6d2466a42d28550e33e4146928280a - -PODFILE CHECKSUM: 140d612345f5f5eda8a7ae30f1ccf4e0b07aced5 - -COCOAPODS: 1.16.2 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index eb69bbb2b..08bd47e13 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -8,9 +8,9 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; - 3845DFE0762714C6680D5DFA /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AFA44D9DB464FB85F130C5B5 /* Pods_Runner.framework */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; + 78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; @@ -30,14 +30,13 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 0ED96167FF623FAB319C6E99 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterGeneratedPluginSwiftPackage; path = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; - 89F44165E15E0A7B109A05EB /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 8D383D452D8E929100066A20 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; @@ -46,8 +45,6 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - AFA44D9DB464FB85F130C5B5 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - C71BAD15819A771165D784B0 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -55,24 +52,17 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 3845DFE0762714C6680D5DFA /* Pods_Runner.framework in Frameworks */, + 78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 23E168F95D2790D29E207E68 /* Frameworks */ = { - isa = PBXGroup; - children = ( - AFA44D9DB464FB85F130C5B5 /* Pods_Runner.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( + 78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 9740EEB21CF90195004384FC /* Debug.xcconfig */, 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, @@ -88,7 +78,6 @@ 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, BB0286322FD60C00014F981C /* Pods */, - 23E168F95D2790D29E207E68 /* Frameworks */, ); sourceTree = ""; }; @@ -119,9 +108,6 @@ BB0286322FD60C00014F981C /* Pods */ = { isa = PBXGroup; children = ( - C71BAD15819A771165D784B0 /* Pods-Runner.debug.xcconfig */, - 0ED96167FF623FAB319C6E99 /* Pods-Runner.release.xcconfig */, - 89F44165E15E0A7B109A05EB /* Pods-Runner.profile.xcconfig */, ); path = Pods; sourceTree = ""; @@ -133,20 +119,21 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( - 49A79EC3F389C902853B9186 /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, - 0A9E38C31DF3DC192213822E /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); dependencies = ( ); name = Runner; + packageProductDependencies = ( + 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */, + ); productName = Runner; productReference = 97C146EE1CF9000F007C117D /* Runner.app */; productType = "com.apple.product-type.application"; @@ -175,6 +162,9 @@ Base, ); mainGroup = 97C146E51CF9000F007C117D; + packageReferences = ( + 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */, + ); productRefGroup = 97C146EF1CF9000F007C117D /* Products */; projectDirPath = ""; projectRoot = ""; @@ -199,23 +189,6 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 0A9E38C31DF3DC192213822E /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", - ); - name = "[CP] Embed Pods Frameworks"; - outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; alwaysOutOfDate = 1; @@ -232,28 +205,6 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; - 49A79EC3F389C902853B9186 /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; alwaysOutOfDate = 1; @@ -581,6 +532,20 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCLocalSwiftPackageReference section */ + 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */ = { + isa = XCLocalSwiftPackageReference; + relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; + }; +/* End XCLocalSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */ = { + isa = XCSwiftPackageProductDependency; + productName = FlutterGeneratedPluginSwiftPackage; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 97C146E61CF9000F007C117D /* Project object */; } diff --git a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index fc5ae0316..0bd6d4227 100644 --- a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -5,6 +5,24 @@ + + + + + + + + + + - - diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 624540307..68c8c578b 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -61,6 +61,19 @@ $(FLUTTER_BUILD_NAME) CFBundleSignature ???? + CFBundleURLTypes + + + CFBundleURLName + de.wger.flutter.app-auth + CFBundleTypeRole + Editor + CFBundleURLSchemes + + wger + + + CFBundleVersion $(FLUTTER_BUILD_NUMBER) LSRequiresIPhoneOS diff --git a/lib/core/error_dialogs.dart b/lib/core/error_dialogs.dart new file mode 100644 index 000000000..50c1def02 --- /dev/null +++ b/lib/core/error_dialogs.dart @@ -0,0 +1,483 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2020 - 2026 wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_html/flutter_html.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:logging/logging.dart'; +import 'package:url_launcher/url_launcher.dart'; +import 'package:wger/core/exceptions/http_exception.dart'; +import 'package:wger/helpers/errors.dart'; +import 'package:wger/helpers/logs.dart'; +import 'package:wger/l10n/generated/app_localizations.dart'; +import 'package:wger/main.dart'; +import 'package:wger/models/workouts/log.dart'; +import 'package:wger/providers/workout_logs_notifier.dart'; + +/// Whether an error dialog is currently on screen. +/// +/// Errors can fire in quick succession; this guards against stacking several +/// modal dialogs on top of each other. +bool _errorDialogVisible = false; + +void showHttpExceptionErrorDialog(WgerHttpException exception, {BuildContext? context}) { + final logger = Logger('showHttpExceptionErrorDialog'); + + // Attempt to get the BuildContext from our global navigatorKey. + // This allows us to show a dialog even if the error occurs outside + // of a widget's build method. + final BuildContext? dialogContext = context ?? navigatorKey.currentContext; + + if (dialogContext == null) { + if (kDebugMode) { + logger.warning('Error: Could not error show http error dialog because the context is null.'); + } + return; + } + + if (_errorDialogVisible) { + logger.info('Suppressing error dialog, one is already visible: $exception'); + return; + } + _errorDialogVisible = true; + + showDialog( + context: dialogContext, + builder: (ctx) => AlertDialog( + title: Text(AppLocalizations.of(ctx).anErrorOccurred), + content: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + if (exception.type == ErrorType.html) + ServerHtmlError(data: exception.htmlError) + else + ...formatApiErrors(extractErrors(exception.errors)), + ], + ), + ), + actions: [ + TextButton( + child: Text(MaterialLocalizations.of(ctx).closeButtonLabel), + onPressed: () { + Navigator.of(ctx).pop(); + }, + ), + ], + ), + ).whenComplete(() => _errorDialogVisible = false); +} + +void showGeneralErrorDialog(dynamic error, StackTrace? stackTrace, {BuildContext? context}) { + // Attempt to get the BuildContext from our global navigatorKey. + // This allows us to show a dialog even if the error occurs outside + // of a widget's build method. + final BuildContext? dialogContext = context ?? navigatorKey.currentContext; + + final logger = Logger('showGeneralErrorDialog'); + + if (dialogContext == null) { + if (kDebugMode) { + logger.warning('Error: Could not error show dialog because the context is null.'); + } + return; + } + + if (_errorDialogVisible) { + logger.info('Suppressing error dialog, one is already visible: $error'); + return; + } + _errorDialogVisible = true; + + final i18n = AppLocalizations.of(dialogContext); + + // If possible, determine the issue title and message based on the error type. + // (Note that issue titles and error messages are not localized) + String issueTitle = 'An error occurred'; + String issueErrorMessage = error.toString(); + + if (error is FlutterErrorDetails) { + issueTitle = 'Application Error'; + issueErrorMessage = error.exceptionAsString(); + } else if (error is MissingRequiredKeysException) { + issueTitle = 'Missing Required Key'; + } + + final String fullStackTrace = stackTrace?.toString() ?? 'No stack trace available.'; + final applicationLogs = InMemoryLogStore().getFormattedLogs(); + + showDialog( + context: dialogContext, + barrierDismissible: false, + builder: (BuildContext context) { + return AlertDialog( + title: Row( + spacing: 8, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon(Icons.error, color: Theme.of(context).colorScheme.error), + Expanded( + child: Text( + i18n.anErrorOccurred, + style: TextStyle(color: Theme.of(context).colorScheme.error), + ), + ), + ], + ), + content: SingleChildScrollView( + child: ListBody( + children: [ + Text(i18n.errorInfoDescription), + const SizedBox(height: 8), + Text(i18n.errorInfoDescription2), + const SizedBox(height: 10), + ExpansionTile( + tilePadding: EdgeInsets.zero, + title: Text(i18n.errorViewDetails), + children: [ + Text( + issueErrorMessage, + style: const TextStyle(fontWeight: FontWeight.bold), + ), + Container( + alignment: Alignment.topLeft, + padding: const EdgeInsets.symmetric(vertical: 8.0), + constraints: const BoxConstraints(maxHeight: 250), + child: SingleChildScrollView( + child: Text( + fullStackTrace, + style: TextStyle(fontSize: 12.0, color: Colors.grey[700]), + ), + ), + ), + CopyToClipboardButton( + text: + 'Error Title: $issueTitle\n' + 'Error Message: $issueErrorMessage\n\n' + 'Stack Trace:\n$fullStackTrace', + ), + const SizedBox(height: 8), + Text(i18n.applicationLogs, style: const TextStyle(fontWeight: FontWeight.bold)), + Container( + alignment: Alignment.topLeft, + padding: const EdgeInsets.symmetric(vertical: 8.0), + constraints: const BoxConstraints(maxHeight: 250), + child: SingleChildScrollView( + child: Column( + children: [ + ...applicationLogs.map( + (entry) => Text( + entry, + style: TextStyle(fontSize: 12.0, color: Colors.grey[700]), + ), + ), + ], + ), + ), + ), + CopyToClipboardButton(text: applicationLogs.join('\n')), + ], + ), + ], + ), + ), + actions: [ + TextButton( + child: const Text('Report issue'), + onPressed: () async { + final githubIssueUrl = buildGithubIssueUrl( + issueTitle: issueTitle, + issueErrorMessage: issueErrorMessage, + stackTrace: fullStackTrace, + applicationLogs: applicationLogs, + ); + final Uri reportUri = Uri.parse(githubIssueUrl); + + try { + await launchUrl(reportUri, mode: LaunchMode.externalApplication); + } catch (e) { + if (kDebugMode) { + logger.warning('Error launching URL: $e'); + } + ScaffoldMessenger.of( + context, + ).showSnackBar(SnackBar(content: Text('Error opening issue tracker: $e'))); + } + }, + ), + FilledButton( + child: Text(MaterialLocalizations.of(context).okButtonLabel), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ).whenComplete(() => _errorDialogVisible = false); +} + +/// Routes [error] to the appropriate UI based on its [ErrorSeverity]. +/// +/// The caller is responsible for logging the error beforehand. +void handleError(Object? error, StackTrace? stackTrace) { + switch (classifyError(error)) { + case ErrorSeverity.cosmetic: + break; + case ErrorSeverity.transient: + showTransientErrorSnackbar(); + case ErrorSeverity.fatal: + if (error is WgerHttpException) { + showHttpExceptionErrorDialog(error); + } else { + showGeneralErrorDialog(error, stackTrace); + } + } +} + +/// Shows a brief, non-blocking snackbar telling the user about a (hopefully) +/// transient error such as network problems, etc. +void showTransientErrorSnackbar() { + final messenger = scaffoldMessengerKey.currentState; + final context = navigatorKey.currentContext; + + if (messenger == null || context == null) { + if (kDebugMode) { + Logger( + 'showNetworkErrorSnackbar', + ).warning('Could not show snackbar: no messenger or context available.'); + } + return; + } + + messenger + ..clearSnackBars() + ..showSnackBar( + SnackBar(content: Text(AppLocalizations.of(context).errorCouldNotConnectToServer)), + ); +} + +/// Shows a brief, non-blocking snackbar telling the user their session is no +/// longer valid and they need to log in again. +void showSessionExpiredSnackbar() { + final messenger = scaffoldMessengerKey.currentState; + final context = navigatorKey.currentContext; + + if (messenger == null || context == null) { + return; + } + + messenger + ..clearSnackBars() + ..showSnackBar( + SnackBar(content: Text(AppLocalizations.of(context).sessionExpired)), + ); +} + +/// A widget to render HTML errors returned by the server +/// +/// This is a simple wrapper around the `Html` Widget, with some light changes +/// to the style. +class ServerHtmlError extends StatelessWidget { + final logger = Logger('ServerHtml'); + final String data; + + ServerHtmlError({required this.data, super.key}); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + + return Html( + data: data, + style: { + 'h1': Style(fontSize: FontSize(theme.textTheme.bodyLarge?.fontSize ?? 15)), + 'h2': Style(fontSize: FontSize(theme.textTheme.bodyMedium?.fontSize ?? 15)), + }, + doNotRenderTheseTags: const {'a'}, + ); + } +} + +class CopyToClipboardButton extends StatelessWidget { + final logger = Logger('CopyToClipboardButton'); + final String text; + + CopyToClipboardButton({required this.text, super.key}); + + @override + Widget build(BuildContext context) { + final i18n = AppLocalizations.of(context); + + return TextButton.icon( + icon: const Icon(Icons.copy_all_outlined, size: 18), + label: Text(i18n.copyToClipboard), + style: TextButton.styleFrom( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + tapTargetSize: MaterialTapTargetSize.shrinkWrap, + ), + onPressed: () { + Clipboard.setData(ClipboardData(text: text)) + .then((_) { + if (context.mounted) { + ScaffoldMessenger.of( + context, + ).showSnackBar(const SnackBar(content: Text('Details copied to clipboard!'))); + } + }) + .catchError((copyError) { + logger.warning('Error copying to clipboard: $copyError'); + + if (context.mounted) { + ScaffoldMessenger.of( + context, + ).showSnackBar(const SnackBar(content: Text('Could not copy details.'))); + } + }); + }, + ); + } +} + +void showDeleteLogDialog(BuildContext context, String confirmDeleteName, Log log) async { + final res = await showDialog( + context: context, + builder: (BuildContext contextDialog) { + return AlertDialog( + content: Text(AppLocalizations.of(context).confirmDelete(confirmDeleteName)), + actions: [ + TextButton( + key: const ValueKey('cancel-button'), + child: Text(MaterialLocalizations.of(context).cancelButtonLabel), + onPressed: () => Navigator.of(contextDialog).pop(), + ), + TextButton( + key: const ValueKey('delete-button'), + child: Text( + AppLocalizations.of(context).delete, + style: TextStyle(color: Theme.of(context).colorScheme.error), + ), + onPressed: () async { + await ProviderScope.containerOf( + context, + ).read(workoutLogProvider).deleteEntry(log.id.toString()); + + Navigator.of(contextDialog).pop(); + + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + AppLocalizations.of(context).successfullyDeleted, + textAlign: TextAlign.center, + ), + ), + ); + }, + ), + ], + ); + }, + ); + return res; +} + +/// Processes the error messages from the server and returns a list of widgets +List formatApiErrors(List errors, {Color? color}) { + final logger = Logger('formatApiErrors'); + final textColor = color ?? Colors.black; + + final List errorList = []; + + for (final error in errors) { + errorList.add( + Text( + error.key, + style: TextStyle(fontWeight: FontWeight.bold, color: textColor), + ), + ); + + logger.warning(error.errorMessages); + for (final message in error.errorMessages) { + errorList.add(Text(message, style: TextStyle(color: textColor))); + } + errorList.add(const SizedBox(height: 8)); + } + + return errorList; +} + +/// Processes the error messages from the server and returns a list of widgets +List formatTextErrors(List errors, {String? title, Color? color}) { + final textColor = color ?? Colors.black; + + final List errorList = []; + + if (title != null) { + errorList.add( + Text( + title, + style: TextStyle(fontWeight: FontWeight.bold, color: textColor), + ), + ); + } + + for (final message in errors) { + errorList.add(Text(message, style: TextStyle(color: textColor))); + } + errorList.add(const SizedBox(height: 8)); + + return errorList; +} + +class FormHttpErrorsWidget extends StatelessWidget { + final WgerHttpException exception; + + const FormHttpErrorsWidget(this.exception, {super.key}); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + + return Container( + constraints: const BoxConstraints(maxHeight: 250), + decoration: BoxDecoration( + border: Border.all(color: theme.colorScheme.error, width: 1), + borderRadius: BorderRadius.circular(6), + ), + padding: const EdgeInsets.all(10), + child: SingleChildScrollView( + child: Column( + children: [ + Icon(Icons.error_outline, color: theme.colorScheme.error), + if (exception.type == ErrorType.html) + ServerHtmlError(data: exception.htmlError) + else + ...formatApiErrors( + extractErrors(exception.errors), + color: theme.colorScheme.error, + ), + ], + ), + ), + ); + } +} diff --git a/lib/core/exceptions/mfa_required_exception.dart b/lib/core/exceptions/mfa_required_exception.dart new file mode 100644 index 000000000..f90f5f9b2 --- /dev/null +++ b/lib/core/exceptions/mfa_required_exception.dart @@ -0,0 +1,35 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 - 2026 wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +/// Thrown when an `allauth.headless` login or signup response indicates that +/// the user must complete a second authentication factor before the session +/// can be issued tokens. +/// +/// The [sessionToken] carries the short-lived flow handle that the follow-up +/// call to `auth/2fa/authenticate` must echo back. [availableFactors] lists +/// the supported factor ids ('totp', 'recovery_codes', 'webauthn') when the +/// server included them, so the UI can pick the right input affordance. +class MfaRequiredException implements Exception { + final String sessionToken; + final List availableFactors; + + const MfaRequiredException({required this.sessionToken, this.availableFactors = const []}); + + @override + String toString() => 'MfaRequiredException(factors: $availableFactors, sessionToken: )'; +} diff --git a/lib/core/locator.dart b/lib/core/locator.dart deleted file mode 100644 index ff8f2ed29..000000000 --- a/lib/core/locator.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'dart:developer'; -import 'dart:io'; - -import 'package:drift/native.dart'; -import 'package:get_it/get_it.dart'; -import 'package:wger/database/exercises/exercise_database.dart'; -import 'package:wger/database/ingredients/ingredients_database.dart'; - -final locator = GetIt.asNewInstance(); - -class ServiceLocator { - factory ServiceLocator() => _singleton; - - const ServiceLocator._internal(); - - static const ServiceLocator _singleton = ServiceLocator._internal(); - - Future _initDB() async { - ExerciseDatabase exerciseDB; - IngredientDatabase ingredientDB; - - if (Platform.environment.containsKey('FLUTTER_TEST')) { - exerciseDB = ExerciseDatabase.inMemory(NativeDatabase.memory()); - ingredientDB = IngredientDatabase.inMemory(NativeDatabase.memory()); - } else { - exerciseDB = ExerciseDatabase(); - ingredientDB = IngredientDatabase(); - } - - locator.registerSingleton(exerciseDB); - locator.registerSingleton(ingredientDB); - } - - Future configure() async { - try { - await _initDB(); - } catch (e, _) { - log(e.toString()); - rethrow; - } - } -} diff --git a/lib/database/converters/exercise_image_style_converter.dart b/lib/database/converters/exercise_image_style_converter.dart new file mode 100644 index 000000000..c1e9377ff --- /dev/null +++ b/lib/database/converters/exercise_image_style_converter.dart @@ -0,0 +1,32 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2020 - 2026 wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:drift/drift.dart'; +import 'package:wger/models/exercises/image.dart'; + +/// Maps an [ExerciseImageStyle] to and from the Django wire format +/// (`'1'`–`'5'`). +class ExerciseImageStyleConverter extends TypeConverter { + const ExerciseImageStyleConverter(); + + @override + ExerciseImageStyle fromSql(String fromDb) => ExerciseImageStyle.fromWire(fromDb); + + @override + String toSql(ExerciseImageStyle value) => value.wireValue; +} diff --git a/lib/database/converters/time_of_day_converter.dart b/lib/database/converters/time_of_day_converter.dart new file mode 100644 index 000000000..b5ca35bf8 --- /dev/null +++ b/lib/database/converters/time_of_day_converter.dart @@ -0,0 +1,35 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2020, 2020- wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:drift/drift.dart'; +import 'package:flutter/material.dart'; +import 'package:wger/helpers/json.dart'; + +class TimeOfDayConverter extends TypeConverter { + const TimeOfDayConverter(); + + @override + TimeOfDay fromSql(String fromDb) { + return stringToTimeNull(fromDb)!; + } + + @override + String toSql(TimeOfDay value) { + return timeToString(value)!; + } +} diff --git a/lib/database/converters/workout_impression_converter.dart b/lib/database/converters/workout_impression_converter.dart new file mode 100644 index 000000000..c7824be09 --- /dev/null +++ b/lib/database/converters/workout_impression_converter.dart @@ -0,0 +1,32 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2020 - 2026 wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:drift/drift.dart'; +import 'package:wger/models/workouts/session.dart'; + +/// Maps a [WorkoutImpression] to and from the Django wire format +/// (`'1'`, `'2'`, `'3'`). +class WorkoutImpressionConverter extends TypeConverter { + const WorkoutImpressionConverter(); + + @override + WorkoutImpression fromSql(String fromDb) => WorkoutImpression.fromWire(fromDb); + + @override + String toSql(WorkoutImpression value) => value.wireValue; +} diff --git a/lib/database/exercises/exercise_database.dart b/lib/database/exercises/exercise_database.dart deleted file mode 100644 index 1cbff2113..000000000 --- a/lib/database/exercises/exercise_database.dart +++ /dev/null @@ -1,129 +0,0 @@ -/* - * This file is part of wger Workout Manager . - * Copyright (c) 2026 wger Team - * - * wger Workout Manager is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import 'package:drift/drift.dart'; -import 'package:drift_flutter/drift_flutter.dart'; -import 'package:logging/logging.dart'; -import 'package:wger/database/exercises/type_converters.dart'; -import 'package:wger/models/exercises/category.dart'; -import 'package:wger/models/exercises/equipment.dart'; -import 'package:wger/models/exercises/language.dart'; -import 'package:wger/models/exercises/muscle.dart'; - -part 'exercise_database.g.dart'; - -@DataClassName('ExerciseTable') -class Exercises extends Table { - const Exercises(); - - IntColumn get id => integer()(); - - TextColumn get data => text()(); - - // TextColumn get data => text().map(const ExerciseBaseConverter())(); - - DateTimeColumn get lastUpdate => dateTime()(); - - /// The date when the exercise was last fetched from the API. While we know - /// when the exercise itself was last updated in `lastUpdate`, we can save - /// ourselves a lot of requests if we don't check too often - DateTimeColumn get lastFetched => dateTime()(); -} - -@DataClassName('MuscleTable') -class Muscles extends Table { - const Muscles(); - - IntColumn get id => integer()(); - - TextColumn get data => text().map(const MuscleConverter())(); -} - -@DataClassName('CategoryTable') -class Categories extends Table { - const Categories(); - - IntColumn get id => integer()(); - - TextColumn get data => text().map(const ExerciseCategoryConverter())(); -} - -@DataClassName('LanguagesTable') -class Languages extends Table { - const Languages(); - - IntColumn get id => integer()(); - - TextColumn get data => text().map(const LanguageConverter())(); -} - -@DataClassName('EquipmentTable') -class Equipments extends Table { - const Equipments(); - - IntColumn get id => integer()(); - - TextColumn get data => text().map(const EquipmentConverter())(); -} - -@DriftDatabase(tables: [Exercises, Muscles, Equipments, Categories, Languages]) -class ExerciseDatabase extends _$ExerciseDatabase { - final _logger = Logger('ExerciseDatabase'); - - ExerciseDatabase() : super(_openConnection()); - - // Named constructor for creating in-memory database - ExerciseDatabase.inMemory(super.e); - - /// Note that this needs to be bumped if the JSON response from the server changes - @override - int get schemaVersion => 4; - - /// There is not really a migration strategy. If we bump the version - /// number, delete everything and recreate the new tables. The provider - /// will fetch everything as needed from the server - @override - MigrationStrategy get migration => MigrationStrategy( - onUpgrade: (m, from, to) async { - // no-op, but needs to be defined - return; - }, - beforeOpen: (openingDetails) async { - if (openingDetails.hadUpgrade) { - final m = createMigrator(); - for (final table in allTables) { - await m.deleteTable(table.actualTableName); - await m.createTable(table); - } - } - }, - ); - - Future deleteEverything() { - return transaction(() async { - for (final table in allTables) { - _logger.info('Deleting db cache table ${table.actualTableName}'); - await delete(table).go(); - } - }); - } -} - -QueryExecutor _openConnection() { - return driftDatabase(name: 'exercises'); -} diff --git a/lib/database/exercises/exercise_database.g.dart b/lib/database/exercises/exercise_database.g.dart deleted file mode 100644 index bfe8ad6e5..000000000 --- a/lib/database/exercises/exercise_database.g.dart +++ /dev/null @@ -1,1854 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'exercise_database.dart'; - -// ignore_for_file: type=lint -class $ExercisesTable extends Exercises with TableInfo<$ExercisesTable, ExerciseTable> { - @override - final GeneratedDatabase attachedDatabase; - final String? _alias; - $ExercisesTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _idMeta = const VerificationMeta('id'); - @override - late final GeneratedColumn id = GeneratedColumn( - 'id', - aliasedName, - false, - type: DriftSqlType.int, - requiredDuringInsert: true, - ); - static const VerificationMeta _dataMeta = const VerificationMeta('data'); - @override - late final GeneratedColumn data = GeneratedColumn( - 'data', - aliasedName, - false, - type: DriftSqlType.string, - requiredDuringInsert: true, - ); - static const VerificationMeta _lastUpdateMeta = const VerificationMeta( - 'lastUpdate', - ); - @override - late final GeneratedColumn lastUpdate = GeneratedColumn( - 'last_update', - aliasedName, - false, - type: DriftSqlType.dateTime, - requiredDuringInsert: true, - ); - static const VerificationMeta _lastFetchedMeta = const VerificationMeta( - 'lastFetched', - ); - @override - late final GeneratedColumn lastFetched = GeneratedColumn( - 'last_fetched', - aliasedName, - false, - type: DriftSqlType.dateTime, - requiredDuringInsert: true, - ); - @override - List get $columns => [id, data, lastUpdate, lastFetched]; - @override - String get aliasedName => _alias ?? actualTableName; - @override - String get actualTableName => $name; - static const String $name = 'exercises'; - @override - VerificationContext validateIntegrity( - Insertable instance, { - bool isInserting = false, - }) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('id')) { - context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); - } else if (isInserting) { - context.missing(_idMeta); - } - if (data.containsKey('data')) { - context.handle( - _dataMeta, - this.data.isAcceptableOrUnknown(data['data']!, _dataMeta), - ); - } else if (isInserting) { - context.missing(_dataMeta); - } - if (data.containsKey('last_update')) { - context.handle( - _lastUpdateMeta, - lastUpdate.isAcceptableOrUnknown(data['last_update']!, _lastUpdateMeta), - ); - } else if (isInserting) { - context.missing(_lastUpdateMeta); - } - if (data.containsKey('last_fetched')) { - context.handle( - _lastFetchedMeta, - lastFetched.isAcceptableOrUnknown( - data['last_fetched']!, - _lastFetchedMeta, - ), - ); - } else if (isInserting) { - context.missing(_lastFetchedMeta); - } - return context; - } - - @override - Set get $primaryKey => const {}; - @override - ExerciseTable map(Map data, {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return ExerciseTable( - id: attachedDatabase.typeMapping.read( - DriftSqlType.int, - data['${effectivePrefix}id'], - )!, - data: attachedDatabase.typeMapping.read( - DriftSqlType.string, - data['${effectivePrefix}data'], - )!, - lastUpdate: attachedDatabase.typeMapping.read( - DriftSqlType.dateTime, - data['${effectivePrefix}last_update'], - )!, - lastFetched: attachedDatabase.typeMapping.read( - DriftSqlType.dateTime, - data['${effectivePrefix}last_fetched'], - )!, - ); - } - - @override - $ExercisesTable createAlias(String alias) { - return $ExercisesTable(attachedDatabase, alias); - } -} - -class ExerciseTable extends DataClass implements Insertable { - final int id; - final String data; - final DateTime lastUpdate; - - /// The date when the exercise was last fetched from the API. While we know - /// when the exercise itself was last updated in `lastUpdate`, we can save - /// ourselves a lot of requests if we don't check too often - final DateTime lastFetched; - const ExerciseTable({ - required this.id, - required this.data, - required this.lastUpdate, - required this.lastFetched, - }); - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - map['id'] = Variable(id); - map['data'] = Variable(data); - map['last_update'] = Variable(lastUpdate); - map['last_fetched'] = Variable(lastFetched); - return map; - } - - ExercisesCompanion toCompanion(bool nullToAbsent) { - return ExercisesCompanion( - id: Value(id), - data: Value(data), - lastUpdate: Value(lastUpdate), - lastFetched: Value(lastFetched), - ); - } - - factory ExerciseTable.fromJson( - Map json, { - ValueSerializer? serializer, - }) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return ExerciseTable( - id: serializer.fromJson(json['id']), - data: serializer.fromJson(json['data']), - lastUpdate: serializer.fromJson(json['lastUpdate']), - lastFetched: serializer.fromJson(json['lastFetched']), - ); - } - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'id': serializer.toJson(id), - 'data': serializer.toJson(data), - 'lastUpdate': serializer.toJson(lastUpdate), - 'lastFetched': serializer.toJson(lastFetched), - }; - } - - ExerciseTable copyWith({ - int? id, - String? data, - DateTime? lastUpdate, - DateTime? lastFetched, - }) => ExerciseTable( - id: id ?? this.id, - data: data ?? this.data, - lastUpdate: lastUpdate ?? this.lastUpdate, - lastFetched: lastFetched ?? this.lastFetched, - ); - ExerciseTable copyWithCompanion(ExercisesCompanion data) { - return ExerciseTable( - id: data.id.present ? data.id.value : this.id, - data: data.data.present ? data.data.value : this.data, - lastUpdate: data.lastUpdate.present ? data.lastUpdate.value : this.lastUpdate, - lastFetched: data.lastFetched.present ? data.lastFetched.value : this.lastFetched, - ); - } - - @override - String toString() { - return (StringBuffer('ExerciseTable(') - ..write('id: $id, ') - ..write('data: $data, ') - ..write('lastUpdate: $lastUpdate, ') - ..write('lastFetched: $lastFetched') - ..write(')')) - .toString(); - } - - @override - int get hashCode => Object.hash(id, data, lastUpdate, lastFetched); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is ExerciseTable && - other.id == this.id && - other.data == this.data && - other.lastUpdate == this.lastUpdate && - other.lastFetched == this.lastFetched); -} - -class ExercisesCompanion extends UpdateCompanion { - final Value id; - final Value data; - final Value lastUpdate; - final Value lastFetched; - final Value rowid; - const ExercisesCompanion({ - this.id = const Value.absent(), - this.data = const Value.absent(), - this.lastUpdate = const Value.absent(), - this.lastFetched = const Value.absent(), - this.rowid = const Value.absent(), - }); - ExercisesCompanion.insert({ - required int id, - required String data, - required DateTime lastUpdate, - required DateTime lastFetched, - this.rowid = const Value.absent(), - }) : id = Value(id), - data = Value(data), - lastUpdate = Value(lastUpdate), - lastFetched = Value(lastFetched); - static Insertable custom({ - Expression? id, - Expression? data, - Expression? lastUpdate, - Expression? lastFetched, - Expression? rowid, - }) { - return RawValuesInsertable({ - if (id != null) 'id': id, - if (data != null) 'data': data, - if (lastUpdate != null) 'last_update': lastUpdate, - if (lastFetched != null) 'last_fetched': lastFetched, - if (rowid != null) 'rowid': rowid, - }); - } - - ExercisesCompanion copyWith({ - Value? id, - Value? data, - Value? lastUpdate, - Value? lastFetched, - Value? rowid, - }) { - return ExercisesCompanion( - id: id ?? this.id, - data: data ?? this.data, - lastUpdate: lastUpdate ?? this.lastUpdate, - lastFetched: lastFetched ?? this.lastFetched, - rowid: rowid ?? this.rowid, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (id.present) { - map['id'] = Variable(id.value); - } - if (data.present) { - map['data'] = Variable(data.value); - } - if (lastUpdate.present) { - map['last_update'] = Variable(lastUpdate.value); - } - if (lastFetched.present) { - map['last_fetched'] = Variable(lastFetched.value); - } - if (rowid.present) { - map['rowid'] = Variable(rowid.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('ExercisesCompanion(') - ..write('id: $id, ') - ..write('data: $data, ') - ..write('lastUpdate: $lastUpdate, ') - ..write('lastFetched: $lastFetched, ') - ..write('rowid: $rowid') - ..write(')')) - .toString(); - } -} - -class $MusclesTable extends Muscles with TableInfo<$MusclesTable, MuscleTable> { - @override - final GeneratedDatabase attachedDatabase; - final String? _alias; - $MusclesTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _idMeta = const VerificationMeta('id'); - @override - late final GeneratedColumn id = GeneratedColumn( - 'id', - aliasedName, - false, - type: DriftSqlType.int, - requiredDuringInsert: true, - ); - @override - late final GeneratedColumnWithTypeConverter data = GeneratedColumn( - 'data', - aliasedName, - false, - type: DriftSqlType.string, - requiredDuringInsert: true, - ).withConverter($MusclesTable.$converterdata); - @override - List get $columns => [id, data]; - @override - String get aliasedName => _alias ?? actualTableName; - @override - String get actualTableName => $name; - static const String $name = 'muscles'; - @override - VerificationContext validateIntegrity( - Insertable instance, { - bool isInserting = false, - }) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('id')) { - context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); - } else if (isInserting) { - context.missing(_idMeta); - } - return context; - } - - @override - Set get $primaryKey => const {}; - @override - MuscleTable map(Map data, {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return MuscleTable( - id: attachedDatabase.typeMapping.read( - DriftSqlType.int, - data['${effectivePrefix}id'], - )!, - data: $MusclesTable.$converterdata.fromSql( - attachedDatabase.typeMapping.read( - DriftSqlType.string, - data['${effectivePrefix}data'], - )!, - ), - ); - } - - @override - $MusclesTable createAlias(String alias) { - return $MusclesTable(attachedDatabase, alias); - } - - static TypeConverter $converterdata = const MuscleConverter(); -} - -class MuscleTable extends DataClass implements Insertable { - final int id; - final Muscle data; - const MuscleTable({required this.id, required this.data}); - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - map['id'] = Variable(id); - { - map['data'] = Variable($MusclesTable.$converterdata.toSql(data)); - } - return map; - } - - MusclesCompanion toCompanion(bool nullToAbsent) { - return MusclesCompanion(id: Value(id), data: Value(data)); - } - - factory MuscleTable.fromJson( - Map json, { - ValueSerializer? serializer, - }) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return MuscleTable( - id: serializer.fromJson(json['id']), - data: serializer.fromJson(json['data']), - ); - } - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'id': serializer.toJson(id), - 'data': serializer.toJson(data), - }; - } - - MuscleTable copyWith({int? id, Muscle? data}) => - MuscleTable(id: id ?? this.id, data: data ?? this.data); - MuscleTable copyWithCompanion(MusclesCompanion data) { - return MuscleTable( - id: data.id.present ? data.id.value : this.id, - data: data.data.present ? data.data.value : this.data, - ); - } - - @override - String toString() { - return (StringBuffer('MuscleTable(') - ..write('id: $id, ') - ..write('data: $data') - ..write(')')) - .toString(); - } - - @override - int get hashCode => Object.hash(id, data); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is MuscleTable && other.id == this.id && other.data == this.data); -} - -class MusclesCompanion extends UpdateCompanion { - final Value id; - final Value data; - final Value rowid; - const MusclesCompanion({ - this.id = const Value.absent(), - this.data = const Value.absent(), - this.rowid = const Value.absent(), - }); - MusclesCompanion.insert({ - required int id, - required Muscle data, - this.rowid = const Value.absent(), - }) : id = Value(id), - data = Value(data); - static Insertable custom({ - Expression? id, - Expression? data, - Expression? rowid, - }) { - return RawValuesInsertable({ - if (id != null) 'id': id, - if (data != null) 'data': data, - if (rowid != null) 'rowid': rowid, - }); - } - - MusclesCompanion copyWith({ - Value? id, - Value? data, - Value? rowid, - }) { - return MusclesCompanion( - id: id ?? this.id, - data: data ?? this.data, - rowid: rowid ?? this.rowid, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (id.present) { - map['id'] = Variable(id.value); - } - if (data.present) { - map['data'] = Variable( - $MusclesTable.$converterdata.toSql(data.value), - ); - } - if (rowid.present) { - map['rowid'] = Variable(rowid.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('MusclesCompanion(') - ..write('id: $id, ') - ..write('data: $data, ') - ..write('rowid: $rowid') - ..write(')')) - .toString(); - } -} - -class $EquipmentsTable extends Equipments with TableInfo<$EquipmentsTable, EquipmentTable> { - @override - final GeneratedDatabase attachedDatabase; - final String? _alias; - $EquipmentsTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _idMeta = const VerificationMeta('id'); - @override - late final GeneratedColumn id = GeneratedColumn( - 'id', - aliasedName, - false, - type: DriftSqlType.int, - requiredDuringInsert: true, - ); - @override - late final GeneratedColumnWithTypeConverter data = GeneratedColumn( - 'data', - aliasedName, - false, - type: DriftSqlType.string, - requiredDuringInsert: true, - ).withConverter($EquipmentsTable.$converterdata); - @override - List get $columns => [id, data]; - @override - String get aliasedName => _alias ?? actualTableName; - @override - String get actualTableName => $name; - static const String $name = 'equipments'; - @override - VerificationContext validateIntegrity( - Insertable instance, { - bool isInserting = false, - }) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('id')) { - context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); - } else if (isInserting) { - context.missing(_idMeta); - } - return context; - } - - @override - Set get $primaryKey => const {}; - @override - EquipmentTable map(Map data, {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return EquipmentTable( - id: attachedDatabase.typeMapping.read( - DriftSqlType.int, - data['${effectivePrefix}id'], - )!, - data: $EquipmentsTable.$converterdata.fromSql( - attachedDatabase.typeMapping.read( - DriftSqlType.string, - data['${effectivePrefix}data'], - )!, - ), - ); - } - - @override - $EquipmentsTable createAlias(String alias) { - return $EquipmentsTable(attachedDatabase, alias); - } - - static TypeConverter $converterdata = const EquipmentConverter(); -} - -class EquipmentTable extends DataClass implements Insertable { - final int id; - final Equipment data; - const EquipmentTable({required this.id, required this.data}); - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - map['id'] = Variable(id); - { - map['data'] = Variable( - $EquipmentsTable.$converterdata.toSql(data), - ); - } - return map; - } - - EquipmentsCompanion toCompanion(bool nullToAbsent) { - return EquipmentsCompanion(id: Value(id), data: Value(data)); - } - - factory EquipmentTable.fromJson( - Map json, { - ValueSerializer? serializer, - }) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return EquipmentTable( - id: serializer.fromJson(json['id']), - data: serializer.fromJson(json['data']), - ); - } - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'id': serializer.toJson(id), - 'data': serializer.toJson(data), - }; - } - - EquipmentTable copyWith({int? id, Equipment? data}) => - EquipmentTable(id: id ?? this.id, data: data ?? this.data); - EquipmentTable copyWithCompanion(EquipmentsCompanion data) { - return EquipmentTable( - id: data.id.present ? data.id.value : this.id, - data: data.data.present ? data.data.value : this.data, - ); - } - - @override - String toString() { - return (StringBuffer('EquipmentTable(') - ..write('id: $id, ') - ..write('data: $data') - ..write(')')) - .toString(); - } - - @override - int get hashCode => Object.hash(id, data); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is EquipmentTable && other.id == this.id && other.data == this.data); -} - -class EquipmentsCompanion extends UpdateCompanion { - final Value id; - final Value data; - final Value rowid; - const EquipmentsCompanion({ - this.id = const Value.absent(), - this.data = const Value.absent(), - this.rowid = const Value.absent(), - }); - EquipmentsCompanion.insert({ - required int id, - required Equipment data, - this.rowid = const Value.absent(), - }) : id = Value(id), - data = Value(data); - static Insertable custom({ - Expression? id, - Expression? data, - Expression? rowid, - }) { - return RawValuesInsertable({ - if (id != null) 'id': id, - if (data != null) 'data': data, - if (rowid != null) 'rowid': rowid, - }); - } - - EquipmentsCompanion copyWith({ - Value? id, - Value? data, - Value? rowid, - }) { - return EquipmentsCompanion( - id: id ?? this.id, - data: data ?? this.data, - rowid: rowid ?? this.rowid, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (id.present) { - map['id'] = Variable(id.value); - } - if (data.present) { - map['data'] = Variable( - $EquipmentsTable.$converterdata.toSql(data.value), - ); - } - if (rowid.present) { - map['rowid'] = Variable(rowid.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('EquipmentsCompanion(') - ..write('id: $id, ') - ..write('data: $data, ') - ..write('rowid: $rowid') - ..write(')')) - .toString(); - } -} - -class $CategoriesTable extends Categories with TableInfo<$CategoriesTable, CategoryTable> { - @override - final GeneratedDatabase attachedDatabase; - final String? _alias; - $CategoriesTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _idMeta = const VerificationMeta('id'); - @override - late final GeneratedColumn id = GeneratedColumn( - 'id', - aliasedName, - false, - type: DriftSqlType.int, - requiredDuringInsert: true, - ); - @override - late final GeneratedColumnWithTypeConverter data = - GeneratedColumn( - 'data', - aliasedName, - false, - type: DriftSqlType.string, - requiredDuringInsert: true, - ).withConverter($CategoriesTable.$converterdata); - @override - List get $columns => [id, data]; - @override - String get aliasedName => _alias ?? actualTableName; - @override - String get actualTableName => $name; - static const String $name = 'categories'; - @override - VerificationContext validateIntegrity( - Insertable instance, { - bool isInserting = false, - }) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('id')) { - context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); - } else if (isInserting) { - context.missing(_idMeta); - } - return context; - } - - @override - Set get $primaryKey => const {}; - @override - CategoryTable map(Map data, {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return CategoryTable( - id: attachedDatabase.typeMapping.read( - DriftSqlType.int, - data['${effectivePrefix}id'], - )!, - data: $CategoriesTable.$converterdata.fromSql( - attachedDatabase.typeMapping.read( - DriftSqlType.string, - data['${effectivePrefix}data'], - )!, - ), - ); - } - - @override - $CategoriesTable createAlias(String alias) { - return $CategoriesTable(attachedDatabase, alias); - } - - static TypeConverter $converterdata = const ExerciseCategoryConverter(); -} - -class CategoryTable extends DataClass implements Insertable { - final int id; - final ExerciseCategory data; - const CategoryTable({required this.id, required this.data}); - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - map['id'] = Variable(id); - { - map['data'] = Variable( - $CategoriesTable.$converterdata.toSql(data), - ); - } - return map; - } - - CategoriesCompanion toCompanion(bool nullToAbsent) { - return CategoriesCompanion(id: Value(id), data: Value(data)); - } - - factory CategoryTable.fromJson( - Map json, { - ValueSerializer? serializer, - }) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return CategoryTable( - id: serializer.fromJson(json['id']), - data: serializer.fromJson(json['data']), - ); - } - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'id': serializer.toJson(id), - 'data': serializer.toJson(data), - }; - } - - CategoryTable copyWith({int? id, ExerciseCategory? data}) => - CategoryTable(id: id ?? this.id, data: data ?? this.data); - CategoryTable copyWithCompanion(CategoriesCompanion data) { - return CategoryTable( - id: data.id.present ? data.id.value : this.id, - data: data.data.present ? data.data.value : this.data, - ); - } - - @override - String toString() { - return (StringBuffer('CategoryTable(') - ..write('id: $id, ') - ..write('data: $data') - ..write(')')) - .toString(); - } - - @override - int get hashCode => Object.hash(id, data); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is CategoryTable && other.id == this.id && other.data == this.data); -} - -class CategoriesCompanion extends UpdateCompanion { - final Value id; - final Value data; - final Value rowid; - const CategoriesCompanion({ - this.id = const Value.absent(), - this.data = const Value.absent(), - this.rowid = const Value.absent(), - }); - CategoriesCompanion.insert({ - required int id, - required ExerciseCategory data, - this.rowid = const Value.absent(), - }) : id = Value(id), - data = Value(data); - static Insertable custom({ - Expression? id, - Expression? data, - Expression? rowid, - }) { - return RawValuesInsertable({ - if (id != null) 'id': id, - if (data != null) 'data': data, - if (rowid != null) 'rowid': rowid, - }); - } - - CategoriesCompanion copyWith({ - Value? id, - Value? data, - Value? rowid, - }) { - return CategoriesCompanion( - id: id ?? this.id, - data: data ?? this.data, - rowid: rowid ?? this.rowid, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (id.present) { - map['id'] = Variable(id.value); - } - if (data.present) { - map['data'] = Variable( - $CategoriesTable.$converterdata.toSql(data.value), - ); - } - if (rowid.present) { - map['rowid'] = Variable(rowid.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('CategoriesCompanion(') - ..write('id: $id, ') - ..write('data: $data, ') - ..write('rowid: $rowid') - ..write(')')) - .toString(); - } -} - -class $LanguagesTable extends Languages with TableInfo<$LanguagesTable, LanguagesTable> { - @override - final GeneratedDatabase attachedDatabase; - final String? _alias; - $LanguagesTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _idMeta = const VerificationMeta('id'); - @override - late final GeneratedColumn id = GeneratedColumn( - 'id', - aliasedName, - false, - type: DriftSqlType.int, - requiredDuringInsert: true, - ); - @override - late final GeneratedColumnWithTypeConverter data = GeneratedColumn( - 'data', - aliasedName, - false, - type: DriftSqlType.string, - requiredDuringInsert: true, - ).withConverter($LanguagesTable.$converterdata); - @override - List get $columns => [id, data]; - @override - String get aliasedName => _alias ?? actualTableName; - @override - String get actualTableName => $name; - static const String $name = 'languages'; - @override - VerificationContext validateIntegrity( - Insertable instance, { - bool isInserting = false, - }) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('id')) { - context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); - } else if (isInserting) { - context.missing(_idMeta); - } - return context; - } - - @override - Set get $primaryKey => const {}; - @override - LanguagesTable map(Map data, {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return LanguagesTable( - id: attachedDatabase.typeMapping.read( - DriftSqlType.int, - data['${effectivePrefix}id'], - )!, - data: $LanguagesTable.$converterdata.fromSql( - attachedDatabase.typeMapping.read( - DriftSqlType.string, - data['${effectivePrefix}data'], - )!, - ), - ); - } - - @override - $LanguagesTable createAlias(String alias) { - return $LanguagesTable(attachedDatabase, alias); - } - - static TypeConverter $converterdata = const LanguageConverter(); -} - -class LanguagesTable extends DataClass implements Insertable { - final int id; - final Language data; - const LanguagesTable({required this.id, required this.data}); - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - map['id'] = Variable(id); - { - map['data'] = Variable( - $LanguagesTable.$converterdata.toSql(data), - ); - } - return map; - } - - LanguagesCompanion toCompanion(bool nullToAbsent) { - return LanguagesCompanion(id: Value(id), data: Value(data)); - } - - factory LanguagesTable.fromJson( - Map json, { - ValueSerializer? serializer, - }) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return LanguagesTable( - id: serializer.fromJson(json['id']), - data: serializer.fromJson(json['data']), - ); - } - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'id': serializer.toJson(id), - 'data': serializer.toJson(data), - }; - } - - LanguagesTable copyWith({int? id, Language? data}) => - LanguagesTable(id: id ?? this.id, data: data ?? this.data); - LanguagesTable copyWithCompanion(LanguagesCompanion data) { - return LanguagesTable( - id: data.id.present ? data.id.value : this.id, - data: data.data.present ? data.data.value : this.data, - ); - } - - @override - String toString() { - return (StringBuffer('LanguagesTable(') - ..write('id: $id, ') - ..write('data: $data') - ..write(')')) - .toString(); - } - - @override - int get hashCode => Object.hash(id, data); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is LanguagesTable && other.id == this.id && other.data == this.data); -} - -class LanguagesCompanion extends UpdateCompanion { - final Value id; - final Value data; - final Value rowid; - const LanguagesCompanion({ - this.id = const Value.absent(), - this.data = const Value.absent(), - this.rowid = const Value.absent(), - }); - LanguagesCompanion.insert({ - required int id, - required Language data, - this.rowid = const Value.absent(), - }) : id = Value(id), - data = Value(data); - static Insertable custom({ - Expression? id, - Expression? data, - Expression? rowid, - }) { - return RawValuesInsertable({ - if (id != null) 'id': id, - if (data != null) 'data': data, - if (rowid != null) 'rowid': rowid, - }); - } - - LanguagesCompanion copyWith({ - Value? id, - Value? data, - Value? rowid, - }) { - return LanguagesCompanion( - id: id ?? this.id, - data: data ?? this.data, - rowid: rowid ?? this.rowid, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (id.present) { - map['id'] = Variable(id.value); - } - if (data.present) { - map['data'] = Variable( - $LanguagesTable.$converterdata.toSql(data.value), - ); - } - if (rowid.present) { - map['rowid'] = Variable(rowid.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('LanguagesCompanion(') - ..write('id: $id, ') - ..write('data: $data, ') - ..write('rowid: $rowid') - ..write(')')) - .toString(); - } -} - -abstract class _$ExerciseDatabase extends GeneratedDatabase { - _$ExerciseDatabase(QueryExecutor e) : super(e); - $ExerciseDatabaseManager get managers => $ExerciseDatabaseManager(this); - late final $ExercisesTable exercises = $ExercisesTable(this); - late final $MusclesTable muscles = $MusclesTable(this); - late final $EquipmentsTable equipments = $EquipmentsTable(this); - late final $CategoriesTable categories = $CategoriesTable(this); - late final $LanguagesTable languages = $LanguagesTable(this); - @override - Iterable> get allTables => - allSchemaEntities.whereType>(); - @override - List get allSchemaEntities => [ - exercises, - muscles, - equipments, - categories, - languages, - ]; -} - -typedef $$ExercisesTableCreateCompanionBuilder = - ExercisesCompanion Function({ - required int id, - required String data, - required DateTime lastUpdate, - required DateTime lastFetched, - Value rowid, - }); -typedef $$ExercisesTableUpdateCompanionBuilder = - ExercisesCompanion Function({ - Value id, - Value data, - Value lastUpdate, - Value lastFetched, - Value rowid, - }); - -class $$ExercisesTableFilterComposer extends Composer<_$ExerciseDatabase, $ExercisesTable> { - $$ExercisesTableFilterComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnFilters get id => $composableBuilder( - column: $table.id, - builder: (column) => ColumnFilters(column), - ); - - ColumnFilters get data => $composableBuilder( - column: $table.data, - builder: (column) => ColumnFilters(column), - ); - - ColumnFilters get lastUpdate => $composableBuilder( - column: $table.lastUpdate, - builder: (column) => ColumnFilters(column), - ); - - ColumnFilters get lastFetched => $composableBuilder( - column: $table.lastFetched, - builder: (column) => ColumnFilters(column), - ); -} - -class $$ExercisesTableOrderingComposer extends Composer<_$ExerciseDatabase, $ExercisesTable> { - $$ExercisesTableOrderingComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnOrderings get id => $composableBuilder( - column: $table.id, - builder: (column) => ColumnOrderings(column), - ); - - ColumnOrderings get data => $composableBuilder( - column: $table.data, - builder: (column) => ColumnOrderings(column), - ); - - ColumnOrderings get lastUpdate => $composableBuilder( - column: $table.lastUpdate, - builder: (column) => ColumnOrderings(column), - ); - - ColumnOrderings get lastFetched => $composableBuilder( - column: $table.lastFetched, - builder: (column) => ColumnOrderings(column), - ); -} - -class $$ExercisesTableAnnotationComposer extends Composer<_$ExerciseDatabase, $ExercisesTable> { - $$ExercisesTableAnnotationComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - GeneratedColumn get id => $composableBuilder(column: $table.id, builder: (column) => column); - - GeneratedColumn get data => - $composableBuilder(column: $table.data, builder: (column) => column); - - GeneratedColumn get lastUpdate => $composableBuilder( - column: $table.lastUpdate, - builder: (column) => column, - ); - - GeneratedColumn get lastFetched => $composableBuilder( - column: $table.lastFetched, - builder: (column) => column, - ); -} - -class $$ExercisesTableTableManager - extends - RootTableManager< - _$ExerciseDatabase, - $ExercisesTable, - ExerciseTable, - $$ExercisesTableFilterComposer, - $$ExercisesTableOrderingComposer, - $$ExercisesTableAnnotationComposer, - $$ExercisesTableCreateCompanionBuilder, - $$ExercisesTableUpdateCompanionBuilder, - ( - ExerciseTable, - BaseReferences<_$ExerciseDatabase, $ExercisesTable, ExerciseTable>, - ), - ExerciseTable, - PrefetchHooks Function() - > { - $$ExercisesTableTableManager(_$ExerciseDatabase db, $ExercisesTable table) - : super( - TableManagerState( - db: db, - table: table, - createFilteringComposer: () => $$ExercisesTableFilterComposer($db: db, $table: table), - createOrderingComposer: () => $$ExercisesTableOrderingComposer($db: db, $table: table), - createComputedFieldComposer: () => - $$ExercisesTableAnnotationComposer($db: db, $table: table), - updateCompanionCallback: - ({ - Value id = const Value.absent(), - Value data = const Value.absent(), - Value lastUpdate = const Value.absent(), - Value lastFetched = const Value.absent(), - Value rowid = const Value.absent(), - }) => ExercisesCompanion( - id: id, - data: data, - lastUpdate: lastUpdate, - lastFetched: lastFetched, - rowid: rowid, - ), - createCompanionCallback: - ({ - required int id, - required String data, - required DateTime lastUpdate, - required DateTime lastFetched, - Value rowid = const Value.absent(), - }) => ExercisesCompanion.insert( - id: id, - data: data, - lastUpdate: lastUpdate, - lastFetched: lastFetched, - rowid: rowid, - ), - withReferenceMapper: (p0) => - p0.map((e) => (e.readTable(table), BaseReferences(db, table, e))).toList(), - prefetchHooksCallback: null, - ), - ); -} - -typedef $$ExercisesTableProcessedTableManager = - ProcessedTableManager< - _$ExerciseDatabase, - $ExercisesTable, - ExerciseTable, - $$ExercisesTableFilterComposer, - $$ExercisesTableOrderingComposer, - $$ExercisesTableAnnotationComposer, - $$ExercisesTableCreateCompanionBuilder, - $$ExercisesTableUpdateCompanionBuilder, - ( - ExerciseTable, - BaseReferences<_$ExerciseDatabase, $ExercisesTable, ExerciseTable>, - ), - ExerciseTable, - PrefetchHooks Function() - >; -typedef $$MusclesTableCreateCompanionBuilder = - MusclesCompanion Function({ - required int id, - required Muscle data, - Value rowid, - }); -typedef $$MusclesTableUpdateCompanionBuilder = - MusclesCompanion Function({ - Value id, - Value data, - Value rowid, - }); - -class $$MusclesTableFilterComposer extends Composer<_$ExerciseDatabase, $MusclesTable> { - $$MusclesTableFilterComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnFilters get id => $composableBuilder( - column: $table.id, - builder: (column) => ColumnFilters(column), - ); - - ColumnWithTypeConverterFilters get data => $composableBuilder( - column: $table.data, - builder: (column) => ColumnWithTypeConverterFilters(column), - ); -} - -class $$MusclesTableOrderingComposer extends Composer<_$ExerciseDatabase, $MusclesTable> { - $$MusclesTableOrderingComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnOrderings get id => $composableBuilder( - column: $table.id, - builder: (column) => ColumnOrderings(column), - ); - - ColumnOrderings get data => $composableBuilder( - column: $table.data, - builder: (column) => ColumnOrderings(column), - ); -} - -class $$MusclesTableAnnotationComposer extends Composer<_$ExerciseDatabase, $MusclesTable> { - $$MusclesTableAnnotationComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - GeneratedColumn get id => $composableBuilder(column: $table.id, builder: (column) => column); - - GeneratedColumnWithTypeConverter get data => - $composableBuilder(column: $table.data, builder: (column) => column); -} - -class $$MusclesTableTableManager - extends - RootTableManager< - _$ExerciseDatabase, - $MusclesTable, - MuscleTable, - $$MusclesTableFilterComposer, - $$MusclesTableOrderingComposer, - $$MusclesTableAnnotationComposer, - $$MusclesTableCreateCompanionBuilder, - $$MusclesTableUpdateCompanionBuilder, - ( - MuscleTable, - BaseReferences<_$ExerciseDatabase, $MusclesTable, MuscleTable>, - ), - MuscleTable, - PrefetchHooks Function() - > { - $$MusclesTableTableManager(_$ExerciseDatabase db, $MusclesTable table) - : super( - TableManagerState( - db: db, - table: table, - createFilteringComposer: () => $$MusclesTableFilterComposer($db: db, $table: table), - createOrderingComposer: () => $$MusclesTableOrderingComposer($db: db, $table: table), - createComputedFieldComposer: () => - $$MusclesTableAnnotationComposer($db: db, $table: table), - updateCompanionCallback: - ({ - Value id = const Value.absent(), - Value data = const Value.absent(), - Value rowid = const Value.absent(), - }) => MusclesCompanion(id: id, data: data, rowid: rowid), - createCompanionCallback: - ({ - required int id, - required Muscle data, - Value rowid = const Value.absent(), - }) => MusclesCompanion.insert(id: id, data: data, rowid: rowid), - withReferenceMapper: (p0) => - p0.map((e) => (e.readTable(table), BaseReferences(db, table, e))).toList(), - prefetchHooksCallback: null, - ), - ); -} - -typedef $$MusclesTableProcessedTableManager = - ProcessedTableManager< - _$ExerciseDatabase, - $MusclesTable, - MuscleTable, - $$MusclesTableFilterComposer, - $$MusclesTableOrderingComposer, - $$MusclesTableAnnotationComposer, - $$MusclesTableCreateCompanionBuilder, - $$MusclesTableUpdateCompanionBuilder, - ( - MuscleTable, - BaseReferences<_$ExerciseDatabase, $MusclesTable, MuscleTable>, - ), - MuscleTable, - PrefetchHooks Function() - >; -typedef $$EquipmentsTableCreateCompanionBuilder = - EquipmentsCompanion Function({ - required int id, - required Equipment data, - Value rowid, - }); -typedef $$EquipmentsTableUpdateCompanionBuilder = - EquipmentsCompanion Function({ - Value id, - Value data, - Value rowid, - }); - -class $$EquipmentsTableFilterComposer extends Composer<_$ExerciseDatabase, $EquipmentsTable> { - $$EquipmentsTableFilterComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnFilters get id => $composableBuilder( - column: $table.id, - builder: (column) => ColumnFilters(column), - ); - - ColumnWithTypeConverterFilters get data => $composableBuilder( - column: $table.data, - builder: (column) => ColumnWithTypeConverterFilters(column), - ); -} - -class $$EquipmentsTableOrderingComposer extends Composer<_$ExerciseDatabase, $EquipmentsTable> { - $$EquipmentsTableOrderingComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnOrderings get id => $composableBuilder( - column: $table.id, - builder: (column) => ColumnOrderings(column), - ); - - ColumnOrderings get data => $composableBuilder( - column: $table.data, - builder: (column) => ColumnOrderings(column), - ); -} - -class $$EquipmentsTableAnnotationComposer extends Composer<_$ExerciseDatabase, $EquipmentsTable> { - $$EquipmentsTableAnnotationComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - GeneratedColumn get id => $composableBuilder(column: $table.id, builder: (column) => column); - - GeneratedColumnWithTypeConverter get data => - $composableBuilder(column: $table.data, builder: (column) => column); -} - -class $$EquipmentsTableTableManager - extends - RootTableManager< - _$ExerciseDatabase, - $EquipmentsTable, - EquipmentTable, - $$EquipmentsTableFilterComposer, - $$EquipmentsTableOrderingComposer, - $$EquipmentsTableAnnotationComposer, - $$EquipmentsTableCreateCompanionBuilder, - $$EquipmentsTableUpdateCompanionBuilder, - ( - EquipmentTable, - BaseReferences<_$ExerciseDatabase, $EquipmentsTable, EquipmentTable>, - ), - EquipmentTable, - PrefetchHooks Function() - > { - $$EquipmentsTableTableManager(_$ExerciseDatabase db, $EquipmentsTable table) - : super( - TableManagerState( - db: db, - table: table, - createFilteringComposer: () => $$EquipmentsTableFilterComposer($db: db, $table: table), - createOrderingComposer: () => $$EquipmentsTableOrderingComposer($db: db, $table: table), - createComputedFieldComposer: () => - $$EquipmentsTableAnnotationComposer($db: db, $table: table), - updateCompanionCallback: - ({ - Value id = const Value.absent(), - Value data = const Value.absent(), - Value rowid = const Value.absent(), - }) => EquipmentsCompanion(id: id, data: data, rowid: rowid), - createCompanionCallback: - ({ - required int id, - required Equipment data, - Value rowid = const Value.absent(), - }) => EquipmentsCompanion.insert(id: id, data: data, rowid: rowid), - withReferenceMapper: (p0) => - p0.map((e) => (e.readTable(table), BaseReferences(db, table, e))).toList(), - prefetchHooksCallback: null, - ), - ); -} - -typedef $$EquipmentsTableProcessedTableManager = - ProcessedTableManager< - _$ExerciseDatabase, - $EquipmentsTable, - EquipmentTable, - $$EquipmentsTableFilterComposer, - $$EquipmentsTableOrderingComposer, - $$EquipmentsTableAnnotationComposer, - $$EquipmentsTableCreateCompanionBuilder, - $$EquipmentsTableUpdateCompanionBuilder, - ( - EquipmentTable, - BaseReferences<_$ExerciseDatabase, $EquipmentsTable, EquipmentTable>, - ), - EquipmentTable, - PrefetchHooks Function() - >; -typedef $$CategoriesTableCreateCompanionBuilder = - CategoriesCompanion Function({ - required int id, - required ExerciseCategory data, - Value rowid, - }); -typedef $$CategoriesTableUpdateCompanionBuilder = - CategoriesCompanion Function({ - Value id, - Value data, - Value rowid, - }); - -class $$CategoriesTableFilterComposer extends Composer<_$ExerciseDatabase, $CategoriesTable> { - $$CategoriesTableFilterComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnFilters get id => $composableBuilder( - column: $table.id, - builder: (column) => ColumnFilters(column), - ); - - ColumnWithTypeConverterFilters get data => - $composableBuilder( - column: $table.data, - builder: (column) => ColumnWithTypeConverterFilters(column), - ); -} - -class $$CategoriesTableOrderingComposer extends Composer<_$ExerciseDatabase, $CategoriesTable> { - $$CategoriesTableOrderingComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnOrderings get id => $composableBuilder( - column: $table.id, - builder: (column) => ColumnOrderings(column), - ); - - ColumnOrderings get data => $composableBuilder( - column: $table.data, - builder: (column) => ColumnOrderings(column), - ); -} - -class $$CategoriesTableAnnotationComposer extends Composer<_$ExerciseDatabase, $CategoriesTable> { - $$CategoriesTableAnnotationComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - GeneratedColumn get id => $composableBuilder(column: $table.id, builder: (column) => column); - - GeneratedColumnWithTypeConverter get data => - $composableBuilder(column: $table.data, builder: (column) => column); -} - -class $$CategoriesTableTableManager - extends - RootTableManager< - _$ExerciseDatabase, - $CategoriesTable, - CategoryTable, - $$CategoriesTableFilterComposer, - $$CategoriesTableOrderingComposer, - $$CategoriesTableAnnotationComposer, - $$CategoriesTableCreateCompanionBuilder, - $$CategoriesTableUpdateCompanionBuilder, - ( - CategoryTable, - BaseReferences<_$ExerciseDatabase, $CategoriesTable, CategoryTable>, - ), - CategoryTable, - PrefetchHooks Function() - > { - $$CategoriesTableTableManager(_$ExerciseDatabase db, $CategoriesTable table) - : super( - TableManagerState( - db: db, - table: table, - createFilteringComposer: () => $$CategoriesTableFilterComposer($db: db, $table: table), - createOrderingComposer: () => $$CategoriesTableOrderingComposer($db: db, $table: table), - createComputedFieldComposer: () => - $$CategoriesTableAnnotationComposer($db: db, $table: table), - updateCompanionCallback: - ({ - Value id = const Value.absent(), - Value data = const Value.absent(), - Value rowid = const Value.absent(), - }) => CategoriesCompanion(id: id, data: data, rowid: rowid), - createCompanionCallback: - ({ - required int id, - required ExerciseCategory data, - Value rowid = const Value.absent(), - }) => CategoriesCompanion.insert(id: id, data: data, rowid: rowid), - withReferenceMapper: (p0) => - p0.map((e) => (e.readTable(table), BaseReferences(db, table, e))).toList(), - prefetchHooksCallback: null, - ), - ); -} - -typedef $$CategoriesTableProcessedTableManager = - ProcessedTableManager< - _$ExerciseDatabase, - $CategoriesTable, - CategoryTable, - $$CategoriesTableFilterComposer, - $$CategoriesTableOrderingComposer, - $$CategoriesTableAnnotationComposer, - $$CategoriesTableCreateCompanionBuilder, - $$CategoriesTableUpdateCompanionBuilder, - ( - CategoryTable, - BaseReferences<_$ExerciseDatabase, $CategoriesTable, CategoryTable>, - ), - CategoryTable, - PrefetchHooks Function() - >; -typedef $$LanguagesTableCreateCompanionBuilder = - LanguagesCompanion Function({ - required int id, - required Language data, - Value rowid, - }); -typedef $$LanguagesTableUpdateCompanionBuilder = - LanguagesCompanion Function({ - Value id, - Value data, - Value rowid, - }); - -class $$LanguagesTableFilterComposer extends Composer<_$ExerciseDatabase, $LanguagesTable> { - $$LanguagesTableFilterComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnFilters get id => $composableBuilder( - column: $table.id, - builder: (column) => ColumnFilters(column), - ); - - ColumnWithTypeConverterFilters get data => $composableBuilder( - column: $table.data, - builder: (column) => ColumnWithTypeConverterFilters(column), - ); -} - -class $$LanguagesTableOrderingComposer extends Composer<_$ExerciseDatabase, $LanguagesTable> { - $$LanguagesTableOrderingComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnOrderings get id => $composableBuilder( - column: $table.id, - builder: (column) => ColumnOrderings(column), - ); - - ColumnOrderings get data => $composableBuilder( - column: $table.data, - builder: (column) => ColumnOrderings(column), - ); -} - -class $$LanguagesTableAnnotationComposer extends Composer<_$ExerciseDatabase, $LanguagesTable> { - $$LanguagesTableAnnotationComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - GeneratedColumn get id => $composableBuilder(column: $table.id, builder: (column) => column); - - GeneratedColumnWithTypeConverter get data => - $composableBuilder(column: $table.data, builder: (column) => column); -} - -class $$LanguagesTableTableManager - extends - RootTableManager< - _$ExerciseDatabase, - $LanguagesTable, - LanguagesTable, - $$LanguagesTableFilterComposer, - $$LanguagesTableOrderingComposer, - $$LanguagesTableAnnotationComposer, - $$LanguagesTableCreateCompanionBuilder, - $$LanguagesTableUpdateCompanionBuilder, - ( - LanguagesTable, - BaseReferences<_$ExerciseDatabase, $LanguagesTable, LanguagesTable>, - ), - LanguagesTable, - PrefetchHooks Function() - > { - $$LanguagesTableTableManager(_$ExerciseDatabase db, $LanguagesTable table) - : super( - TableManagerState( - db: db, - table: table, - createFilteringComposer: () => $$LanguagesTableFilterComposer($db: db, $table: table), - createOrderingComposer: () => $$LanguagesTableOrderingComposer($db: db, $table: table), - createComputedFieldComposer: () => - $$LanguagesTableAnnotationComposer($db: db, $table: table), - updateCompanionCallback: - ({ - Value id = const Value.absent(), - Value data = const Value.absent(), - Value rowid = const Value.absent(), - }) => LanguagesCompanion(id: id, data: data, rowid: rowid), - createCompanionCallback: - ({ - required int id, - required Language data, - Value rowid = const Value.absent(), - }) => LanguagesCompanion.insert(id: id, data: data, rowid: rowid), - withReferenceMapper: (p0) => - p0.map((e) => (e.readTable(table), BaseReferences(db, table, e))).toList(), - prefetchHooksCallback: null, - ), - ); -} - -typedef $$LanguagesTableProcessedTableManager = - ProcessedTableManager< - _$ExerciseDatabase, - $LanguagesTable, - LanguagesTable, - $$LanguagesTableFilterComposer, - $$LanguagesTableOrderingComposer, - $$LanguagesTableAnnotationComposer, - $$LanguagesTableCreateCompanionBuilder, - $$LanguagesTableUpdateCompanionBuilder, - ( - LanguagesTable, - BaseReferences<_$ExerciseDatabase, $LanguagesTable, LanguagesTable>, - ), - LanguagesTable, - PrefetchHooks Function() - >; - -class $ExerciseDatabaseManager { - final _$ExerciseDatabase _db; - $ExerciseDatabaseManager(this._db); - $$ExercisesTableTableManager get exercises => $$ExercisesTableTableManager(_db, _db.exercises); - $$MusclesTableTableManager get muscles => $$MusclesTableTableManager(_db, _db.muscles); - $$EquipmentsTableTableManager get equipments => - $$EquipmentsTableTableManager(_db, _db.equipments); - $$CategoriesTableTableManager get categories => - $$CategoriesTableTableManager(_db, _db.categories); - $$LanguagesTableTableManager get languages => $$LanguagesTableTableManager(_db, _db.languages); -} diff --git a/lib/database/exercises/type_converters.dart b/lib/database/exercises/type_converters.dart deleted file mode 100644 index 755a628b6..000000000 --- a/lib/database/exercises/type_converters.dart +++ /dev/null @@ -1,63 +0,0 @@ -import 'dart:convert'; - -import 'package:drift/drift.dart'; -import 'package:wger/models/exercises/category.dart'; -import 'package:wger/models/exercises/equipment.dart'; -import 'package:wger/models/exercises/language.dart'; -import 'package:wger/models/exercises/muscle.dart'; - -class MuscleConverter extends TypeConverter { - const MuscleConverter(); - - @override - Muscle fromSql(String fromDb) { - return Muscle.fromJson(json.decode(fromDb) as Map); - } - - @override - String toSql(Muscle value) { - return json.encode(value.toJson()); - } -} - -class EquipmentConverter extends TypeConverter { - const EquipmentConverter(); - - @override - Equipment fromSql(String fromDb) { - return Equipment.fromJson(json.decode(fromDb) as Map); - } - - @override - String toSql(Equipment value) { - return json.encode(value.toJson()); - } -} - -class ExerciseCategoryConverter extends TypeConverter { - const ExerciseCategoryConverter(); - - @override - ExerciseCategory fromSql(String fromDb) { - return ExerciseCategory.fromJson(json.decode(fromDb) as Map); - } - - @override - String toSql(ExerciseCategory value) { - return json.encode(value.toJson()); - } -} - -class LanguageConverter extends TypeConverter { - const LanguageConverter(); - - @override - Language fromSql(String fromDb) { - return Language.fromJson(json.decode(fromDb) as Map); - } - - @override - String toSql(Language value) { - return json.encode(value.toJson()); - } -} diff --git a/lib/database/ingredients/ingredients_database.dart b/lib/database/ingredients/ingredients_database.dart deleted file mode 100644 index 0f325e62e..000000000 --- a/lib/database/ingredients/ingredients_database.dart +++ /dev/null @@ -1,64 +0,0 @@ -import 'package:drift/drift.dart'; -import 'package:drift_flutter/drift_flutter.dart'; -import 'package:logging/logging.dart'; - -part 'ingredients_database.g.dart'; - -@DataClassName('IngredientTable') -class Ingredients extends Table { - const Ingredients(); - - IntColumn get id => integer()(); - - TextColumn get data => text()(); - - /// The date when the ingredient was last fetched from the server - DateTimeColumn get lastFetched => dateTime()(); -} - -@DriftDatabase(tables: [Ingredients]) -class IngredientDatabase extends _$IngredientDatabase { - final _logger = Logger('IngredientDatabase'); - - IngredientDatabase() : super(_openConnection()); - - // Named constructor for creating in-memory database - IngredientDatabase.inMemory(super.e); - - /// Note that this needs to be bumped if the JSON response from the server changes - @override - int get schemaVersion => 2; - - /// There is not really a migration strategy. If we bump the version - /// number, delete everything and recreate the new tables. The nutrition provider - /// will fetch everything as needed from the server - @override - MigrationStrategy get migration => MigrationStrategy( - onUpgrade: (m, from, to) async { - // no-op, but needs to be defined - return; - }, - beforeOpen: (openingDetails) async { - if (openingDetails.hadUpgrade) { - final m = createMigrator(); - for (final table in allTables) { - await m.deleteTable(table.actualTableName); - await m.createTable(table); - } - } - }, - ); - - Future deleteEverything() { - return transaction(() async { - for (final table in allTables) { - _logger.info('Deleting db cache table ${table.actualTableName}'); - await delete(table).go(); - } - }); - } -} - -QueryExecutor _openConnection() { - return driftDatabase(name: 'ingredients'); -} diff --git a/lib/database/ingredients/ingredients_database.g.dart b/lib/database/ingredients/ingredients_database.g.dart deleted file mode 100644 index 44ebcde20..000000000 --- a/lib/database/ingredients/ingredients_database.g.dart +++ /dev/null @@ -1,445 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'ingredients_database.dart'; - -// ignore_for_file: type=lint -class $IngredientsTable extends Ingredients with TableInfo<$IngredientsTable, IngredientTable> { - @override - final GeneratedDatabase attachedDatabase; - final String? _alias; - $IngredientsTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _idMeta = const VerificationMeta('id'); - @override - late final GeneratedColumn id = GeneratedColumn( - 'id', - aliasedName, - false, - type: DriftSqlType.int, - requiredDuringInsert: true, - ); - static const VerificationMeta _dataMeta = const VerificationMeta('data'); - @override - late final GeneratedColumn data = GeneratedColumn( - 'data', - aliasedName, - false, - type: DriftSqlType.string, - requiredDuringInsert: true, - ); - static const VerificationMeta _lastFetchedMeta = const VerificationMeta( - 'lastFetched', - ); - @override - late final GeneratedColumn lastFetched = GeneratedColumn( - 'last_fetched', - aliasedName, - false, - type: DriftSqlType.dateTime, - requiredDuringInsert: true, - ); - @override - List get $columns => [id, data, lastFetched]; - @override - String get aliasedName => _alias ?? actualTableName; - @override - String get actualTableName => $name; - static const String $name = 'ingredients'; - @override - VerificationContext validateIntegrity( - Insertable instance, { - bool isInserting = false, - }) { - final context = VerificationContext(); - final data = instance.toColumns(true); - if (data.containsKey('id')) { - context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); - } else if (isInserting) { - context.missing(_idMeta); - } - if (data.containsKey('data')) { - context.handle( - _dataMeta, - this.data.isAcceptableOrUnknown(data['data']!, _dataMeta), - ); - } else if (isInserting) { - context.missing(_dataMeta); - } - if (data.containsKey('last_fetched')) { - context.handle( - _lastFetchedMeta, - lastFetched.isAcceptableOrUnknown( - data['last_fetched']!, - _lastFetchedMeta, - ), - ); - } else if (isInserting) { - context.missing(_lastFetchedMeta); - } - return context; - } - - @override - Set get $primaryKey => const {}; - @override - IngredientTable map(Map data, {String? tablePrefix}) { - final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return IngredientTable( - id: attachedDatabase.typeMapping.read( - DriftSqlType.int, - data['${effectivePrefix}id'], - )!, - data: attachedDatabase.typeMapping.read( - DriftSqlType.string, - data['${effectivePrefix}data'], - )!, - lastFetched: attachedDatabase.typeMapping.read( - DriftSqlType.dateTime, - data['${effectivePrefix}last_fetched'], - )!, - ); - } - - @override - $IngredientsTable createAlias(String alias) { - return $IngredientsTable(attachedDatabase, alias); - } -} - -class IngredientTable extends DataClass implements Insertable { - final int id; - final String data; - - /// The date when the ingredient was last fetched from the server - final DateTime lastFetched; - const IngredientTable({ - required this.id, - required this.data, - required this.lastFetched, - }); - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - map['id'] = Variable(id); - map['data'] = Variable(data); - map['last_fetched'] = Variable(lastFetched); - return map; - } - - IngredientsCompanion toCompanion(bool nullToAbsent) { - return IngredientsCompanion( - id: Value(id), - data: Value(data), - lastFetched: Value(lastFetched), - ); - } - - factory IngredientTable.fromJson( - Map json, { - ValueSerializer? serializer, - }) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return IngredientTable( - id: serializer.fromJson(json['id']), - data: serializer.fromJson(json['data']), - lastFetched: serializer.fromJson(json['lastFetched']), - ); - } - @override - Map toJson({ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return { - 'id': serializer.toJson(id), - 'data': serializer.toJson(data), - 'lastFetched': serializer.toJson(lastFetched), - }; - } - - IngredientTable copyWith({int? id, String? data, DateTime? lastFetched}) => IngredientTable( - id: id ?? this.id, - data: data ?? this.data, - lastFetched: lastFetched ?? this.lastFetched, - ); - IngredientTable copyWithCompanion(IngredientsCompanion data) { - return IngredientTable( - id: data.id.present ? data.id.value : this.id, - data: data.data.present ? data.data.value : this.data, - lastFetched: data.lastFetched.present ? data.lastFetched.value : this.lastFetched, - ); - } - - @override - String toString() { - return (StringBuffer('IngredientTable(') - ..write('id: $id, ') - ..write('data: $data, ') - ..write('lastFetched: $lastFetched') - ..write(')')) - .toString(); - } - - @override - int get hashCode => Object.hash(id, data, lastFetched); - @override - bool operator ==(Object other) => - identical(this, other) || - (other is IngredientTable && - other.id == this.id && - other.data == this.data && - other.lastFetched == this.lastFetched); -} - -class IngredientsCompanion extends UpdateCompanion { - final Value id; - final Value data; - final Value lastFetched; - final Value rowid; - const IngredientsCompanion({ - this.id = const Value.absent(), - this.data = const Value.absent(), - this.lastFetched = const Value.absent(), - this.rowid = const Value.absent(), - }); - IngredientsCompanion.insert({ - required int id, - required String data, - required DateTime lastFetched, - this.rowid = const Value.absent(), - }) : id = Value(id), - data = Value(data), - lastFetched = Value(lastFetched); - static Insertable custom({ - Expression? id, - Expression? data, - Expression? lastFetched, - Expression? rowid, - }) { - return RawValuesInsertable({ - if (id != null) 'id': id, - if (data != null) 'data': data, - if (lastFetched != null) 'last_fetched': lastFetched, - if (rowid != null) 'rowid': rowid, - }); - } - - IngredientsCompanion copyWith({ - Value? id, - Value? data, - Value? lastFetched, - Value? rowid, - }) { - return IngredientsCompanion( - id: id ?? this.id, - data: data ?? this.data, - lastFetched: lastFetched ?? this.lastFetched, - rowid: rowid ?? this.rowid, - ); - } - - @override - Map toColumns(bool nullToAbsent) { - final map = {}; - if (id.present) { - map['id'] = Variable(id.value); - } - if (data.present) { - map['data'] = Variable(data.value); - } - if (lastFetched.present) { - map['last_fetched'] = Variable(lastFetched.value); - } - if (rowid.present) { - map['rowid'] = Variable(rowid.value); - } - return map; - } - - @override - String toString() { - return (StringBuffer('IngredientsCompanion(') - ..write('id: $id, ') - ..write('data: $data, ') - ..write('lastFetched: $lastFetched, ') - ..write('rowid: $rowid') - ..write(')')) - .toString(); - } -} - -abstract class _$IngredientDatabase extends GeneratedDatabase { - _$IngredientDatabase(QueryExecutor e) : super(e); - $IngredientDatabaseManager get managers => $IngredientDatabaseManager(this); - late final $IngredientsTable ingredients = $IngredientsTable(this); - @override - Iterable> get allTables => - allSchemaEntities.whereType>(); - @override - List get allSchemaEntities => [ingredients]; -} - -typedef $$IngredientsTableCreateCompanionBuilder = - IngredientsCompanion Function({ - required int id, - required String data, - required DateTime lastFetched, - Value rowid, - }); -typedef $$IngredientsTableUpdateCompanionBuilder = - IngredientsCompanion Function({ - Value id, - Value data, - Value lastFetched, - Value rowid, - }); - -class $$IngredientsTableFilterComposer extends Composer<_$IngredientDatabase, $IngredientsTable> { - $$IngredientsTableFilterComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnFilters get id => $composableBuilder( - column: $table.id, - builder: (column) => ColumnFilters(column), - ); - - ColumnFilters get data => $composableBuilder( - column: $table.data, - builder: (column) => ColumnFilters(column), - ); - - ColumnFilters get lastFetched => $composableBuilder( - column: $table.lastFetched, - builder: (column) => ColumnFilters(column), - ); -} - -class $$IngredientsTableOrderingComposer extends Composer<_$IngredientDatabase, $IngredientsTable> { - $$IngredientsTableOrderingComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnOrderings get id => $composableBuilder( - column: $table.id, - builder: (column) => ColumnOrderings(column), - ); - - ColumnOrderings get data => $composableBuilder( - column: $table.data, - builder: (column) => ColumnOrderings(column), - ); - - ColumnOrderings get lastFetched => $composableBuilder( - column: $table.lastFetched, - builder: (column) => ColumnOrderings(column), - ); -} - -class $$IngredientsTableAnnotationComposer - extends Composer<_$IngredientDatabase, $IngredientsTable> { - $$IngredientsTableAnnotationComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - GeneratedColumn get id => $composableBuilder(column: $table.id, builder: (column) => column); - - GeneratedColumn get data => - $composableBuilder(column: $table.data, builder: (column) => column); - - GeneratedColumn get lastFetched => $composableBuilder( - column: $table.lastFetched, - builder: (column) => column, - ); -} - -class $$IngredientsTableTableManager - extends - RootTableManager< - _$IngredientDatabase, - $IngredientsTable, - IngredientTable, - $$IngredientsTableFilterComposer, - $$IngredientsTableOrderingComposer, - $$IngredientsTableAnnotationComposer, - $$IngredientsTableCreateCompanionBuilder, - $$IngredientsTableUpdateCompanionBuilder, - ( - IngredientTable, - BaseReferences<_$IngredientDatabase, $IngredientsTable, IngredientTable>, - ), - IngredientTable, - PrefetchHooks Function() - > { - $$IngredientsTableTableManager( - _$IngredientDatabase db, - $IngredientsTable table, - ) : super( - TableManagerState( - db: db, - table: table, - createFilteringComposer: () => $$IngredientsTableFilterComposer($db: db, $table: table), - createOrderingComposer: () => $$IngredientsTableOrderingComposer($db: db, $table: table), - createComputedFieldComposer: () => - $$IngredientsTableAnnotationComposer($db: db, $table: table), - updateCompanionCallback: - ({ - Value id = const Value.absent(), - Value data = const Value.absent(), - Value lastFetched = const Value.absent(), - Value rowid = const Value.absent(), - }) => IngredientsCompanion( - id: id, - data: data, - lastFetched: lastFetched, - rowid: rowid, - ), - createCompanionCallback: - ({ - required int id, - required String data, - required DateTime lastFetched, - Value rowid = const Value.absent(), - }) => IngredientsCompanion.insert( - id: id, - data: data, - lastFetched: lastFetched, - rowid: rowid, - ), - withReferenceMapper: (p0) => - p0.map((e) => (e.readTable(table), BaseReferences(db, table, e))).toList(), - prefetchHooksCallback: null, - ), - ); -} - -typedef $$IngredientsTableProcessedTableManager = - ProcessedTableManager< - _$IngredientDatabase, - $IngredientsTable, - IngredientTable, - $$IngredientsTableFilterComposer, - $$IngredientsTableOrderingComposer, - $$IngredientsTableAnnotationComposer, - $$IngredientsTableCreateCompanionBuilder, - $$IngredientsTableUpdateCompanionBuilder, - ( - IngredientTable, - BaseReferences<_$IngredientDatabase, $IngredientsTable, IngredientTable>, - ), - IngredientTable, - PrefetchHooks Function() - >; - -class $IngredientDatabaseManager { - final _$IngredientDatabase _db; - $IngredientDatabaseManager(this._db); - $$IngredientsTableTableManager get ingredients => - $$IngredientsTableTableManager(_db, _db.ingredients); -} diff --git a/lib/database/powersync/database.dart b/lib/database/powersync/database.dart new file mode 100644 index 000000000..1d2f3e9e1 --- /dev/null +++ b/lib/database/powersync/database.dart @@ -0,0 +1,152 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2020 - 2026 wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:drift/drift.dart'; +import 'package:drift_sqlite_async/drift_sqlite_async.dart'; +import 'package:flutter/material.dart' show TimeOfDay; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:powersync/powersync.dart' as ps; +import 'package:wger/database/converters/exercise_image_style_converter.dart'; +import 'package:wger/database/converters/time_of_day_converter.dart'; +import 'package:wger/database/converters/workout_impression_converter.dart'; +import 'package:wger/models/body_weight/weight_entry.dart'; +import 'package:wger/models/core/language.dart'; +import 'package:wger/models/core/license.dart'; +import 'package:wger/models/exercises/alias.dart'; +import 'package:wger/models/exercises/category.dart'; +import 'package:wger/models/exercises/comment.dart'; +import 'package:wger/models/exercises/equipment.dart'; +import 'package:wger/models/exercises/image.dart'; +import 'package:wger/models/exercises/muscle.dart'; +import 'package:wger/models/exercises/video.dart'; +import 'package:wger/models/gallery/image.dart'; +import 'package:wger/models/measurements/measurement_category.dart'; +import 'package:wger/models/measurements/measurement_entry.dart'; +import 'package:wger/models/nutrition/ingredient.dart'; +import 'package:wger/models/nutrition/ingredient_image.dart'; +import 'package:wger/models/nutrition/ingredient_weight_unit.dart'; +import 'package:wger/models/nutrition/log.dart'; +import 'package:wger/models/nutrition/meal.dart'; +import 'package:wger/models/nutrition/meal_item.dart'; +import 'package:wger/models/nutrition/nutritional_plan.dart'; +import 'package:wger/models/user/user_profile.dart'; +import 'package:wger/models/workouts/log.dart'; +import 'package:wger/models/workouts/repetition_unit.dart'; +import 'package:wger/models/workouts/routine.dart'; +import 'package:wger/models/workouts/session.dart'; +import 'package:wger/models/workouts/weight_unit.dart'; + +import 'powersync.dart'; +import 'tables/exercise.dart'; +import 'tables/gallery.dart'; +import 'tables/ingredient.dart'; +import 'tables/language.dart'; +import 'tables/license.dart'; +import 'tables/measurements.dart'; +import 'tables/nutrition.dart'; +import 'tables/routines.dart'; +import 'tables/user_profile.dart'; +import 'tables/weight.dart'; + +part 'database.g.dart'; + +@DriftDatabase( + tables: [ + // Core + LanguageTable, + LicenseTable, + UserProfileTable, + + // Exercises + ExerciseTable, + ExerciseTranslationTable, + ExerciseAliasTable, + ExerciseCommentTable, + MuscleTable, + ExerciseMuscleM2N, + ExerciseSecondaryMuscleM2N, + EquipmentTable, + ExerciseEquipmentM2N, + ExerciseCategoryTable, + ExerciseImageTable, + ExerciseVideoTable, + + // Body weight + WeightEntryTable, + + // Measurements + MeasurementCategoryTable, + MeasurementEntryTable, + + // Routines + RoutineTable, + WorkoutLogTable, + WorkoutSessionTable, + RoutineRepetitionUnitTable, + RoutineWeightUnitTable, + + // Nutrition + NutritionalPlanTable, + IngredientTable, + IngredientImageTable, + IngredientWeightUnitTable, + MealTable, + MealItemTable, + LogItemTable, + + // Gallery + GalleryImageTable, + ], + //include: {'queries.drift'}, +) +class DriftPowersyncDatabase extends _$DriftPowersyncDatabase { + DriftPowersyncDatabase(super.e); + + @override + int get schemaVersion => 1; + + @override + MigrationStrategy get migration { + return MigrationStrategy( + onCreate: (m) async { + // We don't have to call createAll(), PowerSync instantiates the schema + // for us. We can use the opportunity to create fts5 indexes though. + }, + onUpgrade: (m, from, to) async { + if (from == 1) { + // await createFts5Tables( + // db: this, + // tableName: 'todos', + // columns: ['description', 'list_id'], + // ); + } + }, + ); + } +} + +final driftPowerSyncDatabase = Provider((ref) { + return DriftPowersyncDatabase( + DatabaseConnection.delayed( + Future(() async { + final database = await ref.read(powerSyncInstanceProvider.future); + return SqliteAsyncDriftConnection(database); + }), + ), + ); +}); diff --git a/lib/database/powersync/database.g.dart b/lib/database/powersync/database.g.dart new file mode 100644 index 000000000..e48a8875c --- /dev/null +++ b/lib/database/powersync/database.g.dart @@ -0,0 +1,22195 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'database.dart'; + +// ignore_for_file: type=lint +class $LanguageTableTable extends LanguageTable with TableInfo<$LanguageTableTable, Language> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $LanguageTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _shortNameMeta = const VerificationMeta( + 'shortName', + ); + @override + late final GeneratedColumn shortName = GeneratedColumn( + 'short_name', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _fullNameMeta = const VerificationMeta( + 'fullName', + ); + @override + late final GeneratedColumn fullName = GeneratedColumn( + 'full_name', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + @override + List get $columns => [id, shortName, fullName]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'core_language'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('short_name')) { + context.handle( + _shortNameMeta, + shortName.isAcceptableOrUnknown(data['short_name']!, _shortNameMeta), + ); + } else if (isInserting) { + context.missing(_shortNameMeta); + } + if (data.containsKey('full_name')) { + context.handle( + _fullNameMeta, + fullName.isAcceptableOrUnknown(data['full_name']!, _fullNameMeta), + ); + } else if (isInserting) { + context.missing(_fullNameMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + Language map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return Language( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + shortName: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}short_name'], + )!, + fullName: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}full_name'], + )!, + ); + } + + @override + $LanguageTableTable createAlias(String alias) { + return $LanguageTableTable(attachedDatabase, alias); + } +} + +class LanguageTableCompanion extends UpdateCompanion { + final Value id; + final Value shortName; + final Value fullName; + final Value rowid; + const LanguageTableCompanion({ + this.id = const Value.absent(), + this.shortName = const Value.absent(), + this.fullName = const Value.absent(), + this.rowid = const Value.absent(), + }); + LanguageTableCompanion.insert({ + required int id, + required String shortName, + required String fullName, + this.rowid = const Value.absent(), + }) : id = Value(id), + shortName = Value(shortName), + fullName = Value(fullName); + static Insertable custom({ + Expression? id, + Expression? shortName, + Expression? fullName, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (shortName != null) 'short_name': shortName, + if (fullName != null) 'full_name': fullName, + if (rowid != null) 'rowid': rowid, + }); + } + + LanguageTableCompanion copyWith({ + Value? id, + Value? shortName, + Value? fullName, + Value? rowid, + }) { + return LanguageTableCompanion( + id: id ?? this.id, + shortName: shortName ?? this.shortName, + fullName: fullName ?? this.fullName, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (shortName.present) { + map['short_name'] = Variable(shortName.value); + } + if (fullName.present) { + map['full_name'] = Variable(fullName.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('LanguageTableCompanion(') + ..write('id: $id, ') + ..write('shortName: $shortName, ') + ..write('fullName: $fullName, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $LicenseTableTable extends LicenseTable with TableInfo<$LicenseTableTable, License> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $LicenseTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _shortNameMeta = const VerificationMeta( + 'shortName', + ); + @override + late final GeneratedColumn shortName = GeneratedColumn( + 'short_name', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _fullNameMeta = const VerificationMeta( + 'fullName', + ); + @override + late final GeneratedColumn fullName = GeneratedColumn( + 'full_name', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _urlMeta = const VerificationMeta('url'); + @override + late final GeneratedColumn url = GeneratedColumn( + 'url', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + @override + List get $columns => [id, shortName, fullName, url]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'core_license'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('short_name')) { + context.handle( + _shortNameMeta, + shortName.isAcceptableOrUnknown(data['short_name']!, _shortNameMeta), + ); + } else if (isInserting) { + context.missing(_shortNameMeta); + } + if (data.containsKey('full_name')) { + context.handle( + _fullNameMeta, + fullName.isAcceptableOrUnknown(data['full_name']!, _fullNameMeta), + ); + } else if (isInserting) { + context.missing(_fullNameMeta); + } + if (data.containsKey('url')) { + context.handle( + _urlMeta, + url.isAcceptableOrUnknown(data['url']!, _urlMeta), + ); + } else if (isInserting) { + context.missing(_urlMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + License map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return License( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + shortName: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}short_name'], + )!, + fullName: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}full_name'], + )!, + url: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}url'], + )!, + ); + } + + @override + $LicenseTableTable createAlias(String alias) { + return $LicenseTableTable(attachedDatabase, alias); + } +} + +class LicenseTableCompanion extends UpdateCompanion { + final Value id; + final Value shortName; + final Value fullName; + final Value url; + final Value rowid; + const LicenseTableCompanion({ + this.id = const Value.absent(), + this.shortName = const Value.absent(), + this.fullName = const Value.absent(), + this.url = const Value.absent(), + this.rowid = const Value.absent(), + }); + LicenseTableCompanion.insert({ + required int id, + required String shortName, + required String fullName, + required String url, + this.rowid = const Value.absent(), + }) : id = Value(id), + shortName = Value(shortName), + fullName = Value(fullName), + url = Value(url); + static Insertable custom({ + Expression? id, + Expression? shortName, + Expression? fullName, + Expression? url, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (shortName != null) 'short_name': shortName, + if (fullName != null) 'full_name': fullName, + if (url != null) 'url': url, + if (rowid != null) 'rowid': rowid, + }); + } + + LicenseTableCompanion copyWith({ + Value? id, + Value? shortName, + Value? fullName, + Value? url, + Value? rowid, + }) { + return LicenseTableCompanion( + id: id ?? this.id, + shortName: shortName ?? this.shortName, + fullName: fullName ?? this.fullName, + url: url ?? this.url, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (shortName.present) { + map['short_name'] = Variable(shortName.value); + } + if (fullName.present) { + map['full_name'] = Variable(fullName.value); + } + if (url.present) { + map['url'] = Variable(url.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('LicenseTableCompanion(') + ..write('id: $id, ') + ..write('shortName: $shortName, ') + ..write('fullName: $fullName, ') + ..write('url: $url, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $UserProfileTableTable extends UserProfileTable + with TableInfo<$UserProfileTableTable, UserProfile> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $UserProfileTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _weightUnitStrMeta = const VerificationMeta( + 'weightUnitStr', + ); + @override + late final GeneratedColumn weightUnitStr = GeneratedColumn( + 'weight_unit', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + @override + List get $columns => [id, weightUnitStr]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'core_userprofile'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('weight_unit')) { + context.handle( + _weightUnitStrMeta, + weightUnitStr.isAcceptableOrUnknown( + data['weight_unit']!, + _weightUnitStrMeta, + ), + ); + } else if (isInserting) { + context.missing(_weightUnitStrMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + UserProfile map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return UserProfile( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + weightUnitStr: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}weight_unit'], + )!, + ); + } + + @override + $UserProfileTableTable createAlias(String alias) { + return $UserProfileTableTable(attachedDatabase, alias); + } +} + +class UserProfileTableCompanion extends UpdateCompanion { + final Value id; + final Value weightUnitStr; + final Value rowid; + const UserProfileTableCompanion({ + this.id = const Value.absent(), + this.weightUnitStr = const Value.absent(), + this.rowid = const Value.absent(), + }); + UserProfileTableCompanion.insert({ + required int id, + required String weightUnitStr, + this.rowid = const Value.absent(), + }) : id = Value(id), + weightUnitStr = Value(weightUnitStr); + static Insertable custom({ + Expression? id, + Expression? weightUnitStr, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (weightUnitStr != null) 'weight_unit': weightUnitStr, + if (rowid != null) 'rowid': rowid, + }); + } + + UserProfileTableCompanion copyWith({ + Value? id, + Value? weightUnitStr, + Value? rowid, + }) { + return UserProfileTableCompanion( + id: id ?? this.id, + weightUnitStr: weightUnitStr ?? this.weightUnitStr, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (weightUnitStr.present) { + map['weight_unit'] = Variable(weightUnitStr.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('UserProfileTableCompanion(') + ..write('id: $id, ') + ..write('weightUnitStr: $weightUnitStr, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $ExerciseCategoryTableTable extends ExerciseCategoryTable + with TableInfo<$ExerciseCategoryTableTable, ExerciseCategory> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $ExerciseCategoryTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _nameMeta = const VerificationMeta('name'); + @override + late final GeneratedColumn name = GeneratedColumn( + 'name', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + @override + List get $columns => [id, name]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'exercises_exercisecategory'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('name')) { + context.handle( + _nameMeta, + name.isAcceptableOrUnknown(data['name']!, _nameMeta), + ); + } else if (isInserting) { + context.missing(_nameMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + ExerciseCategory map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return ExerciseCategory( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + name: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}name'], + )!, + ); + } + + @override + $ExerciseCategoryTableTable createAlias(String alias) { + return $ExerciseCategoryTableTable(attachedDatabase, alias); + } +} + +class ExerciseCategoryTableCompanion extends UpdateCompanion { + final Value id; + final Value name; + final Value rowid; + const ExerciseCategoryTableCompanion({ + this.id = const Value.absent(), + this.name = const Value.absent(), + this.rowid = const Value.absent(), + }); + ExerciseCategoryTableCompanion.insert({ + required int id, + required String name, + this.rowid = const Value.absent(), + }) : id = Value(id), + name = Value(name); + static Insertable custom({ + Expression? id, + Expression? name, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (name != null) 'name': name, + if (rowid != null) 'rowid': rowid, + }); + } + + ExerciseCategoryTableCompanion copyWith({ + Value? id, + Value? name, + Value? rowid, + }) { + return ExerciseCategoryTableCompanion( + id: id ?? this.id, + name: name ?? this.name, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (name.present) { + map['name'] = Variable(name.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('ExerciseCategoryTableCompanion(') + ..write('id: $id, ') + ..write('name: $name, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $ExerciseTableTable extends ExerciseTable with TableInfo<$ExerciseTableTable, ExerciseRow> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $ExerciseTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _uuidMeta = const VerificationMeta('uuid'); + @override + late final GeneratedColumn uuid = GeneratedColumn( + 'uuid', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _variationGroupMeta = const VerificationMeta( + 'variationGroup', + ); + @override + late final GeneratedColumn variationGroup = GeneratedColumn( + 'variation_group', + aliasedName, + true, + type: DriftSqlType.string, + requiredDuringInsert: false, + ); + static const VerificationMeta _categoryIdMeta = const VerificationMeta( + 'categoryId', + ); + @override + late final GeneratedColumn categoryId = GeneratedColumn( + 'category_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES exercises_exercisecategory (id)', + ), + ); + static const VerificationMeta _createdMeta = const VerificationMeta( + 'created', + ); + @override + late final GeneratedColumn created = GeneratedColumn( + 'created', + aliasedName, + false, + type: DriftSqlType.dateTime, + requiredDuringInsert: true, + ); + static const VerificationMeta _lastUpdateMeta = const VerificationMeta( + 'lastUpdate', + ); + @override + late final GeneratedColumn lastUpdate = GeneratedColumn( + 'last_update', + aliasedName, + false, + type: DriftSqlType.dateTime, + requiredDuringInsert: true, + ); + @override + List get $columns => [ + id, + uuid, + variationGroup, + categoryId, + created, + lastUpdate, + ]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'exercises_exercise'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('uuid')) { + context.handle( + _uuidMeta, + uuid.isAcceptableOrUnknown(data['uuid']!, _uuidMeta), + ); + } else if (isInserting) { + context.missing(_uuidMeta); + } + if (data.containsKey('variation_group')) { + context.handle( + _variationGroupMeta, + variationGroup.isAcceptableOrUnknown( + data['variation_group']!, + _variationGroupMeta, + ), + ); + } + if (data.containsKey('category_id')) { + context.handle( + _categoryIdMeta, + categoryId.isAcceptableOrUnknown(data['category_id']!, _categoryIdMeta), + ); + } else if (isInserting) { + context.missing(_categoryIdMeta); + } + if (data.containsKey('created')) { + context.handle( + _createdMeta, + created.isAcceptableOrUnknown(data['created']!, _createdMeta), + ); + } else if (isInserting) { + context.missing(_createdMeta); + } + if (data.containsKey('last_update')) { + context.handle( + _lastUpdateMeta, + lastUpdate.isAcceptableOrUnknown(data['last_update']!, _lastUpdateMeta), + ); + } else if (isInserting) { + context.missing(_lastUpdateMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + ExerciseRow map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return ExerciseRow( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + uuid: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}uuid'], + )!, + variationGroup: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}variation_group'], + ), + categoryId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}category_id'], + )!, + created: attachedDatabase.typeMapping.read( + DriftSqlType.dateTime, + data['${effectivePrefix}created'], + )!, + lastUpdate: attachedDatabase.typeMapping.read( + DriftSqlType.dateTime, + data['${effectivePrefix}last_update'], + )!, + ); + } + + @override + $ExerciseTableTable createAlias(String alias) { + return $ExerciseTableTable(attachedDatabase, alias); + } +} + +class ExerciseRow extends DataClass implements Insertable { + final int id; + final String uuid; + final String? variationGroup; + final int categoryId; + final DateTime created; + final DateTime lastUpdate; + const ExerciseRow({ + required this.id, + required this.uuid, + this.variationGroup, + required this.categoryId, + required this.created, + required this.lastUpdate, + }); + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + map['id'] = Variable(id); + map['uuid'] = Variable(uuid); + if (!nullToAbsent || variationGroup != null) { + map['variation_group'] = Variable(variationGroup); + } + map['category_id'] = Variable(categoryId); + map['created'] = Variable(created); + map['last_update'] = Variable(lastUpdate); + return map; + } + + ExerciseTableCompanion toCompanion(bool nullToAbsent) { + return ExerciseTableCompanion( + id: Value(id), + uuid: Value(uuid), + variationGroup: variationGroup == null && nullToAbsent + ? const Value.absent() + : Value(variationGroup), + categoryId: Value(categoryId), + created: Value(created), + lastUpdate: Value(lastUpdate), + ); + } + + factory ExerciseRow.fromJson( + Map json, { + ValueSerializer? serializer, + }) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return ExerciseRow( + id: serializer.fromJson(json['id']), + uuid: serializer.fromJson(json['uuid']), + variationGroup: serializer.fromJson(json['variationGroup']), + categoryId: serializer.fromJson(json['categoryId']), + created: serializer.fromJson(json['created']), + lastUpdate: serializer.fromJson(json['lastUpdate']), + ); + } + @override + Map toJson({ValueSerializer? serializer}) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return { + 'id': serializer.toJson(id), + 'uuid': serializer.toJson(uuid), + 'variationGroup': serializer.toJson(variationGroup), + 'categoryId': serializer.toJson(categoryId), + 'created': serializer.toJson(created), + 'lastUpdate': serializer.toJson(lastUpdate), + }; + } + + ExerciseRow copyWith({ + int? id, + String? uuid, + Value variationGroup = const Value.absent(), + int? categoryId, + DateTime? created, + DateTime? lastUpdate, + }) => ExerciseRow( + id: id ?? this.id, + uuid: uuid ?? this.uuid, + variationGroup: variationGroup.present ? variationGroup.value : this.variationGroup, + categoryId: categoryId ?? this.categoryId, + created: created ?? this.created, + lastUpdate: lastUpdate ?? this.lastUpdate, + ); + ExerciseRow copyWithCompanion(ExerciseTableCompanion data) { + return ExerciseRow( + id: data.id.present ? data.id.value : this.id, + uuid: data.uuid.present ? data.uuid.value : this.uuid, + variationGroup: data.variationGroup.present ? data.variationGroup.value : this.variationGroup, + categoryId: data.categoryId.present ? data.categoryId.value : this.categoryId, + created: data.created.present ? data.created.value : this.created, + lastUpdate: data.lastUpdate.present ? data.lastUpdate.value : this.lastUpdate, + ); + } + + @override + String toString() { + return (StringBuffer('ExerciseRow(') + ..write('id: $id, ') + ..write('uuid: $uuid, ') + ..write('variationGroup: $variationGroup, ') + ..write('categoryId: $categoryId, ') + ..write('created: $created, ') + ..write('lastUpdate: $lastUpdate') + ..write(')')) + .toString(); + } + + @override + int get hashCode => Object.hash(id, uuid, variationGroup, categoryId, created, lastUpdate); + @override + bool operator ==(Object other) => + identical(this, other) || + (other is ExerciseRow && + other.id == this.id && + other.uuid == this.uuid && + other.variationGroup == this.variationGroup && + other.categoryId == this.categoryId && + other.created == this.created && + other.lastUpdate == this.lastUpdate); +} + +class ExerciseTableCompanion extends UpdateCompanion { + final Value id; + final Value uuid; + final Value variationGroup; + final Value categoryId; + final Value created; + final Value lastUpdate; + final Value rowid; + const ExerciseTableCompanion({ + this.id = const Value.absent(), + this.uuid = const Value.absent(), + this.variationGroup = const Value.absent(), + this.categoryId = const Value.absent(), + this.created = const Value.absent(), + this.lastUpdate = const Value.absent(), + this.rowid = const Value.absent(), + }); + ExerciseTableCompanion.insert({ + required int id, + required String uuid, + this.variationGroup = const Value.absent(), + required int categoryId, + required DateTime created, + required DateTime lastUpdate, + this.rowid = const Value.absent(), + }) : id = Value(id), + uuid = Value(uuid), + categoryId = Value(categoryId), + created = Value(created), + lastUpdate = Value(lastUpdate); + static Insertable custom({ + Expression? id, + Expression? uuid, + Expression? variationGroup, + Expression? categoryId, + Expression? created, + Expression? lastUpdate, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (uuid != null) 'uuid': uuid, + if (variationGroup != null) 'variation_group': variationGroup, + if (categoryId != null) 'category_id': categoryId, + if (created != null) 'created': created, + if (lastUpdate != null) 'last_update': lastUpdate, + if (rowid != null) 'rowid': rowid, + }); + } + + ExerciseTableCompanion copyWith({ + Value? id, + Value? uuid, + Value? variationGroup, + Value? categoryId, + Value? created, + Value? lastUpdate, + Value? rowid, + }) { + return ExerciseTableCompanion( + id: id ?? this.id, + uuid: uuid ?? this.uuid, + variationGroup: variationGroup ?? this.variationGroup, + categoryId: categoryId ?? this.categoryId, + created: created ?? this.created, + lastUpdate: lastUpdate ?? this.lastUpdate, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (uuid.present) { + map['uuid'] = Variable(uuid.value); + } + if (variationGroup.present) { + map['variation_group'] = Variable(variationGroup.value); + } + if (categoryId.present) { + map['category_id'] = Variable(categoryId.value); + } + if (created.present) { + map['created'] = Variable(created.value); + } + if (lastUpdate.present) { + map['last_update'] = Variable(lastUpdate.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('ExerciseTableCompanion(') + ..write('id: $id, ') + ..write('uuid: $uuid, ') + ..write('variationGroup: $variationGroup, ') + ..write('categoryId: $categoryId, ') + ..write('created: $created, ') + ..write('lastUpdate: $lastUpdate, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $ExerciseTranslationTableTable extends ExerciseTranslationTable + with TableInfo<$ExerciseTranslationTableTable, ExerciseTranslationRow> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $ExerciseTranslationTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _uuidMeta = const VerificationMeta('uuid'); + @override + late final GeneratedColumn uuid = GeneratedColumn( + 'uuid', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _exerciseIdMeta = const VerificationMeta( + 'exerciseId', + ); + @override + late final GeneratedColumn exerciseId = GeneratedColumn( + 'exercise_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES exercises_exercise (id)', + ), + ); + static const VerificationMeta _languageIdMeta = const VerificationMeta( + 'languageId', + ); + @override + late final GeneratedColumn languageId = GeneratedColumn( + 'language_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES core_language (id)', + ), + ); + static const VerificationMeta _nameMeta = const VerificationMeta('name'); + @override + late final GeneratedColumn name = GeneratedColumn( + 'name', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _descriptionMeta = const VerificationMeta( + 'description', + ); + @override + late final GeneratedColumn description = GeneratedColumn( + 'description', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _createdMeta = const VerificationMeta( + 'created', + ); + @override + late final GeneratedColumn created = GeneratedColumn( + 'created', + aliasedName, + false, + type: DriftSqlType.dateTime, + requiredDuringInsert: true, + ); + static const VerificationMeta _lastUpdateMeta = const VerificationMeta( + 'lastUpdate', + ); + @override + late final GeneratedColumn lastUpdate = GeneratedColumn( + 'last_update', + aliasedName, + false, + type: DriftSqlType.dateTime, + requiredDuringInsert: true, + ); + @override + List get $columns => [ + id, + uuid, + exerciseId, + languageId, + name, + description, + created, + lastUpdate, + ]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'exercises_translation'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('uuid')) { + context.handle( + _uuidMeta, + uuid.isAcceptableOrUnknown(data['uuid']!, _uuidMeta), + ); + } else if (isInserting) { + context.missing(_uuidMeta); + } + if (data.containsKey('exercise_id')) { + context.handle( + _exerciseIdMeta, + exerciseId.isAcceptableOrUnknown(data['exercise_id']!, _exerciseIdMeta), + ); + } else if (isInserting) { + context.missing(_exerciseIdMeta); + } + if (data.containsKey('language_id')) { + context.handle( + _languageIdMeta, + languageId.isAcceptableOrUnknown(data['language_id']!, _languageIdMeta), + ); + } else if (isInserting) { + context.missing(_languageIdMeta); + } + if (data.containsKey('name')) { + context.handle( + _nameMeta, + name.isAcceptableOrUnknown(data['name']!, _nameMeta), + ); + } else if (isInserting) { + context.missing(_nameMeta); + } + if (data.containsKey('description')) { + context.handle( + _descriptionMeta, + description.isAcceptableOrUnknown( + data['description']!, + _descriptionMeta, + ), + ); + } else if (isInserting) { + context.missing(_descriptionMeta); + } + if (data.containsKey('created')) { + context.handle( + _createdMeta, + created.isAcceptableOrUnknown(data['created']!, _createdMeta), + ); + } else if (isInserting) { + context.missing(_createdMeta); + } + if (data.containsKey('last_update')) { + context.handle( + _lastUpdateMeta, + lastUpdate.isAcceptableOrUnknown(data['last_update']!, _lastUpdateMeta), + ); + } else if (isInserting) { + context.missing(_lastUpdateMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + ExerciseTranslationRow map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return ExerciseTranslationRow( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + uuid: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}uuid'], + )!, + exerciseId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}exercise_id'], + )!, + languageId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}language_id'], + )!, + name: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}name'], + )!, + description: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}description'], + )!, + created: attachedDatabase.typeMapping.read( + DriftSqlType.dateTime, + data['${effectivePrefix}created'], + )!, + lastUpdate: attachedDatabase.typeMapping.read( + DriftSqlType.dateTime, + data['${effectivePrefix}last_update'], + )!, + ); + } + + @override + $ExerciseTranslationTableTable createAlias(String alias) { + return $ExerciseTranslationTableTable(attachedDatabase, alias); + } +} + +class ExerciseTranslationRow extends DataClass implements Insertable { + final int id; + final String uuid; + final int exerciseId; + final int languageId; + final String name; + final String description; + final DateTime created; + final DateTime lastUpdate; + const ExerciseTranslationRow({ + required this.id, + required this.uuid, + required this.exerciseId, + required this.languageId, + required this.name, + required this.description, + required this.created, + required this.lastUpdate, + }); + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + map['id'] = Variable(id); + map['uuid'] = Variable(uuid); + map['exercise_id'] = Variable(exerciseId); + map['language_id'] = Variable(languageId); + map['name'] = Variable(name); + map['description'] = Variable(description); + map['created'] = Variable(created); + map['last_update'] = Variable(lastUpdate); + return map; + } + + ExerciseTranslationTableCompanion toCompanion(bool nullToAbsent) { + return ExerciseTranslationTableCompanion( + id: Value(id), + uuid: Value(uuid), + exerciseId: Value(exerciseId), + languageId: Value(languageId), + name: Value(name), + description: Value(description), + created: Value(created), + lastUpdate: Value(lastUpdate), + ); + } + + factory ExerciseTranslationRow.fromJson( + Map json, { + ValueSerializer? serializer, + }) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return ExerciseTranslationRow( + id: serializer.fromJson(json['id']), + uuid: serializer.fromJson(json['uuid']), + exerciseId: serializer.fromJson(json['exerciseId']), + languageId: serializer.fromJson(json['languageId']), + name: serializer.fromJson(json['name']), + description: serializer.fromJson(json['description']), + created: serializer.fromJson(json['created']), + lastUpdate: serializer.fromJson(json['lastUpdate']), + ); + } + @override + Map toJson({ValueSerializer? serializer}) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return { + 'id': serializer.toJson(id), + 'uuid': serializer.toJson(uuid), + 'exerciseId': serializer.toJson(exerciseId), + 'languageId': serializer.toJson(languageId), + 'name': serializer.toJson(name), + 'description': serializer.toJson(description), + 'created': serializer.toJson(created), + 'lastUpdate': serializer.toJson(lastUpdate), + }; + } + + ExerciseTranslationRow copyWith({ + int? id, + String? uuid, + int? exerciseId, + int? languageId, + String? name, + String? description, + DateTime? created, + DateTime? lastUpdate, + }) => ExerciseTranslationRow( + id: id ?? this.id, + uuid: uuid ?? this.uuid, + exerciseId: exerciseId ?? this.exerciseId, + languageId: languageId ?? this.languageId, + name: name ?? this.name, + description: description ?? this.description, + created: created ?? this.created, + lastUpdate: lastUpdate ?? this.lastUpdate, + ); + ExerciseTranslationRow copyWithCompanion( + ExerciseTranslationTableCompanion data, + ) { + return ExerciseTranslationRow( + id: data.id.present ? data.id.value : this.id, + uuid: data.uuid.present ? data.uuid.value : this.uuid, + exerciseId: data.exerciseId.present ? data.exerciseId.value : this.exerciseId, + languageId: data.languageId.present ? data.languageId.value : this.languageId, + name: data.name.present ? data.name.value : this.name, + description: data.description.present ? data.description.value : this.description, + created: data.created.present ? data.created.value : this.created, + lastUpdate: data.lastUpdate.present ? data.lastUpdate.value : this.lastUpdate, + ); + } + + @override + String toString() { + return (StringBuffer('ExerciseTranslationRow(') + ..write('id: $id, ') + ..write('uuid: $uuid, ') + ..write('exerciseId: $exerciseId, ') + ..write('languageId: $languageId, ') + ..write('name: $name, ') + ..write('description: $description, ') + ..write('created: $created, ') + ..write('lastUpdate: $lastUpdate') + ..write(')')) + .toString(); + } + + @override + int get hashCode => Object.hash( + id, + uuid, + exerciseId, + languageId, + name, + description, + created, + lastUpdate, + ); + @override + bool operator ==(Object other) => + identical(this, other) || + (other is ExerciseTranslationRow && + other.id == this.id && + other.uuid == this.uuid && + other.exerciseId == this.exerciseId && + other.languageId == this.languageId && + other.name == this.name && + other.description == this.description && + other.created == this.created && + other.lastUpdate == this.lastUpdate); +} + +class ExerciseTranslationTableCompanion extends UpdateCompanion { + final Value id; + final Value uuid; + final Value exerciseId; + final Value languageId; + final Value name; + final Value description; + final Value created; + final Value lastUpdate; + final Value rowid; + const ExerciseTranslationTableCompanion({ + this.id = const Value.absent(), + this.uuid = const Value.absent(), + this.exerciseId = const Value.absent(), + this.languageId = const Value.absent(), + this.name = const Value.absent(), + this.description = const Value.absent(), + this.created = const Value.absent(), + this.lastUpdate = const Value.absent(), + this.rowid = const Value.absent(), + }); + ExerciseTranslationTableCompanion.insert({ + required int id, + required String uuid, + required int exerciseId, + required int languageId, + required String name, + required String description, + required DateTime created, + required DateTime lastUpdate, + this.rowid = const Value.absent(), + }) : id = Value(id), + uuid = Value(uuid), + exerciseId = Value(exerciseId), + languageId = Value(languageId), + name = Value(name), + description = Value(description), + created = Value(created), + lastUpdate = Value(lastUpdate); + static Insertable custom({ + Expression? id, + Expression? uuid, + Expression? exerciseId, + Expression? languageId, + Expression? name, + Expression? description, + Expression? created, + Expression? lastUpdate, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (uuid != null) 'uuid': uuid, + if (exerciseId != null) 'exercise_id': exerciseId, + if (languageId != null) 'language_id': languageId, + if (name != null) 'name': name, + if (description != null) 'description': description, + if (created != null) 'created': created, + if (lastUpdate != null) 'last_update': lastUpdate, + if (rowid != null) 'rowid': rowid, + }); + } + + ExerciseTranslationTableCompanion copyWith({ + Value? id, + Value? uuid, + Value? exerciseId, + Value? languageId, + Value? name, + Value? description, + Value? created, + Value? lastUpdate, + Value? rowid, + }) { + return ExerciseTranslationTableCompanion( + id: id ?? this.id, + uuid: uuid ?? this.uuid, + exerciseId: exerciseId ?? this.exerciseId, + languageId: languageId ?? this.languageId, + name: name ?? this.name, + description: description ?? this.description, + created: created ?? this.created, + lastUpdate: lastUpdate ?? this.lastUpdate, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (uuid.present) { + map['uuid'] = Variable(uuid.value); + } + if (exerciseId.present) { + map['exercise_id'] = Variable(exerciseId.value); + } + if (languageId.present) { + map['language_id'] = Variable(languageId.value); + } + if (name.present) { + map['name'] = Variable(name.value); + } + if (description.present) { + map['description'] = Variable(description.value); + } + if (created.present) { + map['created'] = Variable(created.value); + } + if (lastUpdate.present) { + map['last_update'] = Variable(lastUpdate.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('ExerciseTranslationTableCompanion(') + ..write('id: $id, ') + ..write('uuid: $uuid, ') + ..write('exerciseId: $exerciseId, ') + ..write('languageId: $languageId, ') + ..write('name: $name, ') + ..write('description: $description, ') + ..write('created: $created, ') + ..write('lastUpdate: $lastUpdate, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $ExerciseAliasTableTable extends ExerciseAliasTable + with TableInfo<$ExerciseAliasTableTable, Alias> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $ExerciseAliasTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _uuidMeta = const VerificationMeta('uuid'); + @override + late final GeneratedColumn uuid = GeneratedColumn( + 'uuid', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _translationIdMeta = const VerificationMeta( + 'translationId', + ); + @override + late final GeneratedColumn translationId = GeneratedColumn( + 'translation_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES exercises_translation (id)', + ), + ); + static const VerificationMeta _aliasMeta = const VerificationMeta('alias'); + @override + late final GeneratedColumn alias = GeneratedColumn( + 'alias', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + @override + List get $columns => [id, uuid, translationId, alias]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'exercises_alias'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('uuid')) { + context.handle( + _uuidMeta, + uuid.isAcceptableOrUnknown(data['uuid']!, _uuidMeta), + ); + } else if (isInserting) { + context.missing(_uuidMeta); + } + if (data.containsKey('translation_id')) { + context.handle( + _translationIdMeta, + translationId.isAcceptableOrUnknown( + data['translation_id']!, + _translationIdMeta, + ), + ); + } else if (isInserting) { + context.missing(_translationIdMeta); + } + if (data.containsKey('alias')) { + context.handle( + _aliasMeta, + alias.isAcceptableOrUnknown(data['alias']!, _aliasMeta), + ); + } else if (isInserting) { + context.missing(_aliasMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + Alias map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return Alias( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + translationId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}translation_id'], + )!, + alias: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}alias'], + )!, + ); + } + + @override + $ExerciseAliasTableTable createAlias(String alias) { + return $ExerciseAliasTableTable(attachedDatabase, alias); + } +} + +class ExerciseAliasTableCompanion extends UpdateCompanion { + final Value id; + final Value uuid; + final Value translationId; + final Value alias; + final Value rowid; + const ExerciseAliasTableCompanion({ + this.id = const Value.absent(), + this.uuid = const Value.absent(), + this.translationId = const Value.absent(), + this.alias = const Value.absent(), + this.rowid = const Value.absent(), + }); + ExerciseAliasTableCompanion.insert({ + required int id, + required String uuid, + required int translationId, + required String alias, + this.rowid = const Value.absent(), + }) : id = Value(id), + uuid = Value(uuid), + translationId = Value(translationId), + alias = Value(alias); + static Insertable custom({ + Expression? id, + Expression? uuid, + Expression? translationId, + Expression? alias, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (uuid != null) 'uuid': uuid, + if (translationId != null) 'translation_id': translationId, + if (alias != null) 'alias': alias, + if (rowid != null) 'rowid': rowid, + }); + } + + ExerciseAliasTableCompanion copyWith({ + Value? id, + Value? uuid, + Value? translationId, + Value? alias, + Value? rowid, + }) { + return ExerciseAliasTableCompanion( + id: id ?? this.id, + uuid: uuid ?? this.uuid, + translationId: translationId ?? this.translationId, + alias: alias ?? this.alias, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (uuid.present) { + map['uuid'] = Variable(uuid.value); + } + if (translationId.present) { + map['translation_id'] = Variable(translationId.value); + } + if (alias.present) { + map['alias'] = Variable(alias.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('ExerciseAliasTableCompanion(') + ..write('id: $id, ') + ..write('uuid: $uuid, ') + ..write('translationId: $translationId, ') + ..write('alias: $alias, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $ExerciseCommentTableTable extends ExerciseCommentTable + with TableInfo<$ExerciseCommentTableTable, Comment> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $ExerciseCommentTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _uuidMeta = const VerificationMeta('uuid'); + @override + late final GeneratedColumn uuid = GeneratedColumn( + 'uuid', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _translationIdMeta = const VerificationMeta( + 'translationId', + ); + @override + late final GeneratedColumn translationId = GeneratedColumn( + 'translation_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES exercises_translation (id)', + ), + ); + static const VerificationMeta _commentMeta = const VerificationMeta( + 'comment', + ); + @override + late final GeneratedColumn comment = GeneratedColumn( + 'comment', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + @override + List get $columns => [id, uuid, translationId, comment]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'exercises_exercisecomment'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('uuid')) { + context.handle( + _uuidMeta, + uuid.isAcceptableOrUnknown(data['uuid']!, _uuidMeta), + ); + } else if (isInserting) { + context.missing(_uuidMeta); + } + if (data.containsKey('translation_id')) { + context.handle( + _translationIdMeta, + translationId.isAcceptableOrUnknown( + data['translation_id']!, + _translationIdMeta, + ), + ); + } else if (isInserting) { + context.missing(_translationIdMeta); + } + if (data.containsKey('comment')) { + context.handle( + _commentMeta, + comment.isAcceptableOrUnknown(data['comment']!, _commentMeta), + ); + } else if (isInserting) { + context.missing(_commentMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + Comment map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return Comment( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + translationId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}translation_id'], + )!, + comment: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}comment'], + )!, + ); + } + + @override + $ExerciseCommentTableTable createAlias(String alias) { + return $ExerciseCommentTableTable(attachedDatabase, alias); + } +} + +class ExerciseCommentTableCompanion extends UpdateCompanion { + final Value id; + final Value uuid; + final Value translationId; + final Value comment; + final Value rowid; + const ExerciseCommentTableCompanion({ + this.id = const Value.absent(), + this.uuid = const Value.absent(), + this.translationId = const Value.absent(), + this.comment = const Value.absent(), + this.rowid = const Value.absent(), + }); + ExerciseCommentTableCompanion.insert({ + required int id, + required String uuid, + required int translationId, + required String comment, + this.rowid = const Value.absent(), + }) : id = Value(id), + uuid = Value(uuid), + translationId = Value(translationId), + comment = Value(comment); + static Insertable custom({ + Expression? id, + Expression? uuid, + Expression? translationId, + Expression? comment, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (uuid != null) 'uuid': uuid, + if (translationId != null) 'translation_id': translationId, + if (comment != null) 'comment': comment, + if (rowid != null) 'rowid': rowid, + }); + } + + ExerciseCommentTableCompanion copyWith({ + Value? id, + Value? uuid, + Value? translationId, + Value? comment, + Value? rowid, + }) { + return ExerciseCommentTableCompanion( + id: id ?? this.id, + uuid: uuid ?? this.uuid, + translationId: translationId ?? this.translationId, + comment: comment ?? this.comment, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (uuid.present) { + map['uuid'] = Variable(uuid.value); + } + if (translationId.present) { + map['translation_id'] = Variable(translationId.value); + } + if (comment.present) { + map['comment'] = Variable(comment.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('ExerciseCommentTableCompanion(') + ..write('id: $id, ') + ..write('uuid: $uuid, ') + ..write('translationId: $translationId, ') + ..write('comment: $comment, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $MuscleTableTable extends MuscleTable with TableInfo<$MuscleTableTable, Muscle> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $MuscleTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _nameMeta = const VerificationMeta('name'); + @override + late final GeneratedColumn name = GeneratedColumn( + 'name', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _nameEnMeta = const VerificationMeta('nameEn'); + @override + late final GeneratedColumn nameEn = GeneratedColumn( + 'name_en', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _isFrontMeta = const VerificationMeta( + 'isFront', + ); + @override + late final GeneratedColumn isFront = GeneratedColumn( + 'is_front', + aliasedName, + false, + type: DriftSqlType.bool, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'CHECK ("is_front" IN (0, 1))', + ), + ); + @override + List get $columns => [id, name, nameEn, isFront]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'exercises_muscle'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('name')) { + context.handle( + _nameMeta, + name.isAcceptableOrUnknown(data['name']!, _nameMeta), + ); + } else if (isInserting) { + context.missing(_nameMeta); + } + if (data.containsKey('name_en')) { + context.handle( + _nameEnMeta, + nameEn.isAcceptableOrUnknown(data['name_en']!, _nameEnMeta), + ); + } else if (isInserting) { + context.missing(_nameEnMeta); + } + if (data.containsKey('is_front')) { + context.handle( + _isFrontMeta, + isFront.isAcceptableOrUnknown(data['is_front']!, _isFrontMeta), + ); + } else if (isInserting) { + context.missing(_isFrontMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + Muscle map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return Muscle( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + name: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}name'], + )!, + nameEn: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}name_en'], + )!, + isFront: attachedDatabase.typeMapping.read( + DriftSqlType.bool, + data['${effectivePrefix}is_front'], + )!, + ); + } + + @override + $MuscleTableTable createAlias(String alias) { + return $MuscleTableTable(attachedDatabase, alias); + } +} + +class MuscleTableCompanion extends UpdateCompanion { + final Value id; + final Value name; + final Value nameEn; + final Value isFront; + final Value rowid; + const MuscleTableCompanion({ + this.id = const Value.absent(), + this.name = const Value.absent(), + this.nameEn = const Value.absent(), + this.isFront = const Value.absent(), + this.rowid = const Value.absent(), + }); + MuscleTableCompanion.insert({ + required int id, + required String name, + required String nameEn, + required bool isFront, + this.rowid = const Value.absent(), + }) : id = Value(id), + name = Value(name), + nameEn = Value(nameEn), + isFront = Value(isFront); + static Insertable custom({ + Expression? id, + Expression? name, + Expression? nameEn, + Expression? isFront, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (name != null) 'name': name, + if (nameEn != null) 'name_en': nameEn, + if (isFront != null) 'is_front': isFront, + if (rowid != null) 'rowid': rowid, + }); + } + + MuscleTableCompanion copyWith({ + Value? id, + Value? name, + Value? nameEn, + Value? isFront, + Value? rowid, + }) { + return MuscleTableCompanion( + id: id ?? this.id, + name: name ?? this.name, + nameEn: nameEn ?? this.nameEn, + isFront: isFront ?? this.isFront, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (name.present) { + map['name'] = Variable(name.value); + } + if (nameEn.present) { + map['name_en'] = Variable(nameEn.value); + } + if (isFront.present) { + map['is_front'] = Variable(isFront.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('MuscleTableCompanion(') + ..write('id: $id, ') + ..write('name: $name, ') + ..write('nameEn: $nameEn, ') + ..write('isFront: $isFront, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $ExerciseMuscleM2NTable extends ExerciseMuscleM2N + with TableInfo<$ExerciseMuscleM2NTable, ExerciseMuscleM2NData> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $ExerciseMuscleM2NTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _exerciseIdMeta = const VerificationMeta( + 'exerciseId', + ); + @override + late final GeneratedColumn exerciseId = GeneratedColumn( + 'exercise_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES exercises_exercise (id)', + ), + ); + static const VerificationMeta _muscleIdMeta = const VerificationMeta( + 'muscleId', + ); + @override + late final GeneratedColumn muscleId = GeneratedColumn( + 'muscle_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES exercises_muscle (id)', + ), + ); + @override + List get $columns => [id, exerciseId, muscleId]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'exercises_exercise_muscles'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('exercise_id')) { + context.handle( + _exerciseIdMeta, + exerciseId.isAcceptableOrUnknown(data['exercise_id']!, _exerciseIdMeta), + ); + } else if (isInserting) { + context.missing(_exerciseIdMeta); + } + if (data.containsKey('muscle_id')) { + context.handle( + _muscleIdMeta, + muscleId.isAcceptableOrUnknown(data['muscle_id']!, _muscleIdMeta), + ); + } else if (isInserting) { + context.missing(_muscleIdMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + ExerciseMuscleM2NData map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return ExerciseMuscleM2NData( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + exerciseId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}exercise_id'], + )!, + muscleId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}muscle_id'], + )!, + ); + } + + @override + $ExerciseMuscleM2NTable createAlias(String alias) { + return $ExerciseMuscleM2NTable(attachedDatabase, alias); + } +} + +class ExerciseMuscleM2NData extends DataClass implements Insertable { + final int id; + final int exerciseId; + final int muscleId; + const ExerciseMuscleM2NData({ + required this.id, + required this.exerciseId, + required this.muscleId, + }); + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + map['id'] = Variable(id); + map['exercise_id'] = Variable(exerciseId); + map['muscle_id'] = Variable(muscleId); + return map; + } + + ExerciseMuscleM2NCompanion toCompanion(bool nullToAbsent) { + return ExerciseMuscleM2NCompanion( + id: Value(id), + exerciseId: Value(exerciseId), + muscleId: Value(muscleId), + ); + } + + factory ExerciseMuscleM2NData.fromJson( + Map json, { + ValueSerializer? serializer, + }) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return ExerciseMuscleM2NData( + id: serializer.fromJson(json['id']), + exerciseId: serializer.fromJson(json['exerciseId']), + muscleId: serializer.fromJson(json['muscleId']), + ); + } + @override + Map toJson({ValueSerializer? serializer}) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return { + 'id': serializer.toJson(id), + 'exerciseId': serializer.toJson(exerciseId), + 'muscleId': serializer.toJson(muscleId), + }; + } + + ExerciseMuscleM2NData copyWith({int? id, int? exerciseId, int? muscleId}) => + ExerciseMuscleM2NData( + id: id ?? this.id, + exerciseId: exerciseId ?? this.exerciseId, + muscleId: muscleId ?? this.muscleId, + ); + ExerciseMuscleM2NData copyWithCompanion(ExerciseMuscleM2NCompanion data) { + return ExerciseMuscleM2NData( + id: data.id.present ? data.id.value : this.id, + exerciseId: data.exerciseId.present ? data.exerciseId.value : this.exerciseId, + muscleId: data.muscleId.present ? data.muscleId.value : this.muscleId, + ); + } + + @override + String toString() { + return (StringBuffer('ExerciseMuscleM2NData(') + ..write('id: $id, ') + ..write('exerciseId: $exerciseId, ') + ..write('muscleId: $muscleId') + ..write(')')) + .toString(); + } + + @override + int get hashCode => Object.hash(id, exerciseId, muscleId); + @override + bool operator ==(Object other) => + identical(this, other) || + (other is ExerciseMuscleM2NData && + other.id == this.id && + other.exerciseId == this.exerciseId && + other.muscleId == this.muscleId); +} + +class ExerciseMuscleM2NCompanion extends UpdateCompanion { + final Value id; + final Value exerciseId; + final Value muscleId; + final Value rowid; + const ExerciseMuscleM2NCompanion({ + this.id = const Value.absent(), + this.exerciseId = const Value.absent(), + this.muscleId = const Value.absent(), + this.rowid = const Value.absent(), + }); + ExerciseMuscleM2NCompanion.insert({ + required int id, + required int exerciseId, + required int muscleId, + this.rowid = const Value.absent(), + }) : id = Value(id), + exerciseId = Value(exerciseId), + muscleId = Value(muscleId); + static Insertable custom({ + Expression? id, + Expression? exerciseId, + Expression? muscleId, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (exerciseId != null) 'exercise_id': exerciseId, + if (muscleId != null) 'muscle_id': muscleId, + if (rowid != null) 'rowid': rowid, + }); + } + + ExerciseMuscleM2NCompanion copyWith({ + Value? id, + Value? exerciseId, + Value? muscleId, + Value? rowid, + }) { + return ExerciseMuscleM2NCompanion( + id: id ?? this.id, + exerciseId: exerciseId ?? this.exerciseId, + muscleId: muscleId ?? this.muscleId, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (exerciseId.present) { + map['exercise_id'] = Variable(exerciseId.value); + } + if (muscleId.present) { + map['muscle_id'] = Variable(muscleId.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('ExerciseMuscleM2NCompanion(') + ..write('id: $id, ') + ..write('exerciseId: $exerciseId, ') + ..write('muscleId: $muscleId, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $ExerciseSecondaryMuscleM2NTable extends ExerciseSecondaryMuscleM2N + with TableInfo<$ExerciseSecondaryMuscleM2NTable, ExerciseSecondaryMuscleM2NData> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $ExerciseSecondaryMuscleM2NTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _exerciseIdMeta = const VerificationMeta( + 'exerciseId', + ); + @override + late final GeneratedColumn exerciseId = GeneratedColumn( + 'exercise_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES exercises_exercise (id)', + ), + ); + static const VerificationMeta _muscleIdMeta = const VerificationMeta( + 'muscleId', + ); + @override + late final GeneratedColumn muscleId = GeneratedColumn( + 'muscle_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES exercises_muscle (id)', + ), + ); + @override + List get $columns => [id, exerciseId, muscleId]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'exercises_exercise_muscles_secondary'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('exercise_id')) { + context.handle( + _exerciseIdMeta, + exerciseId.isAcceptableOrUnknown(data['exercise_id']!, _exerciseIdMeta), + ); + } else if (isInserting) { + context.missing(_exerciseIdMeta); + } + if (data.containsKey('muscle_id')) { + context.handle( + _muscleIdMeta, + muscleId.isAcceptableOrUnknown(data['muscle_id']!, _muscleIdMeta), + ); + } else if (isInserting) { + context.missing(_muscleIdMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + ExerciseSecondaryMuscleM2NData map( + Map data, { + String? tablePrefix, + }) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return ExerciseSecondaryMuscleM2NData( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + exerciseId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}exercise_id'], + )!, + muscleId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}muscle_id'], + )!, + ); + } + + @override + $ExerciseSecondaryMuscleM2NTable createAlias(String alias) { + return $ExerciseSecondaryMuscleM2NTable(attachedDatabase, alias); + } +} + +class ExerciseSecondaryMuscleM2NData extends DataClass + implements Insertable { + final int id; + final int exerciseId; + final int muscleId; + const ExerciseSecondaryMuscleM2NData({ + required this.id, + required this.exerciseId, + required this.muscleId, + }); + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + map['id'] = Variable(id); + map['exercise_id'] = Variable(exerciseId); + map['muscle_id'] = Variable(muscleId); + return map; + } + + ExerciseSecondaryMuscleM2NCompanion toCompanion(bool nullToAbsent) { + return ExerciseSecondaryMuscleM2NCompanion( + id: Value(id), + exerciseId: Value(exerciseId), + muscleId: Value(muscleId), + ); + } + + factory ExerciseSecondaryMuscleM2NData.fromJson( + Map json, { + ValueSerializer? serializer, + }) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return ExerciseSecondaryMuscleM2NData( + id: serializer.fromJson(json['id']), + exerciseId: serializer.fromJson(json['exerciseId']), + muscleId: serializer.fromJson(json['muscleId']), + ); + } + @override + Map toJson({ValueSerializer? serializer}) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return { + 'id': serializer.toJson(id), + 'exerciseId': serializer.toJson(exerciseId), + 'muscleId': serializer.toJson(muscleId), + }; + } + + ExerciseSecondaryMuscleM2NData copyWith({ + int? id, + int? exerciseId, + int? muscleId, + }) => ExerciseSecondaryMuscleM2NData( + id: id ?? this.id, + exerciseId: exerciseId ?? this.exerciseId, + muscleId: muscleId ?? this.muscleId, + ); + ExerciseSecondaryMuscleM2NData copyWithCompanion( + ExerciseSecondaryMuscleM2NCompanion data, + ) { + return ExerciseSecondaryMuscleM2NData( + id: data.id.present ? data.id.value : this.id, + exerciseId: data.exerciseId.present ? data.exerciseId.value : this.exerciseId, + muscleId: data.muscleId.present ? data.muscleId.value : this.muscleId, + ); + } + + @override + String toString() { + return (StringBuffer('ExerciseSecondaryMuscleM2NData(') + ..write('id: $id, ') + ..write('exerciseId: $exerciseId, ') + ..write('muscleId: $muscleId') + ..write(')')) + .toString(); + } + + @override + int get hashCode => Object.hash(id, exerciseId, muscleId); + @override + bool operator ==(Object other) => + identical(this, other) || + (other is ExerciseSecondaryMuscleM2NData && + other.id == this.id && + other.exerciseId == this.exerciseId && + other.muscleId == this.muscleId); +} + +class ExerciseSecondaryMuscleM2NCompanion extends UpdateCompanion { + final Value id; + final Value exerciseId; + final Value muscleId; + final Value rowid; + const ExerciseSecondaryMuscleM2NCompanion({ + this.id = const Value.absent(), + this.exerciseId = const Value.absent(), + this.muscleId = const Value.absent(), + this.rowid = const Value.absent(), + }); + ExerciseSecondaryMuscleM2NCompanion.insert({ + required int id, + required int exerciseId, + required int muscleId, + this.rowid = const Value.absent(), + }) : id = Value(id), + exerciseId = Value(exerciseId), + muscleId = Value(muscleId); + static Insertable custom({ + Expression? id, + Expression? exerciseId, + Expression? muscleId, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (exerciseId != null) 'exercise_id': exerciseId, + if (muscleId != null) 'muscle_id': muscleId, + if (rowid != null) 'rowid': rowid, + }); + } + + ExerciseSecondaryMuscleM2NCompanion copyWith({ + Value? id, + Value? exerciseId, + Value? muscleId, + Value? rowid, + }) { + return ExerciseSecondaryMuscleM2NCompanion( + id: id ?? this.id, + exerciseId: exerciseId ?? this.exerciseId, + muscleId: muscleId ?? this.muscleId, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (exerciseId.present) { + map['exercise_id'] = Variable(exerciseId.value); + } + if (muscleId.present) { + map['muscle_id'] = Variable(muscleId.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('ExerciseSecondaryMuscleM2NCompanion(') + ..write('id: $id, ') + ..write('exerciseId: $exerciseId, ') + ..write('muscleId: $muscleId, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $EquipmentTableTable extends EquipmentTable with TableInfo<$EquipmentTableTable, Equipment> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $EquipmentTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _nameMeta = const VerificationMeta('name'); + @override + late final GeneratedColumn name = GeneratedColumn( + 'name', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + @override + List get $columns => [id, name]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'exercises_equipment'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('name')) { + context.handle( + _nameMeta, + name.isAcceptableOrUnknown(data['name']!, _nameMeta), + ); + } else if (isInserting) { + context.missing(_nameMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + Equipment map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return Equipment( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + name: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}name'], + )!, + ); + } + + @override + $EquipmentTableTable createAlias(String alias) { + return $EquipmentTableTable(attachedDatabase, alias); + } +} + +class EquipmentTableCompanion extends UpdateCompanion { + final Value id; + final Value name; + final Value rowid; + const EquipmentTableCompanion({ + this.id = const Value.absent(), + this.name = const Value.absent(), + this.rowid = const Value.absent(), + }); + EquipmentTableCompanion.insert({ + required int id, + required String name, + this.rowid = const Value.absent(), + }) : id = Value(id), + name = Value(name); + static Insertable custom({ + Expression? id, + Expression? name, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (name != null) 'name': name, + if (rowid != null) 'rowid': rowid, + }); + } + + EquipmentTableCompanion copyWith({ + Value? id, + Value? name, + Value? rowid, + }) { + return EquipmentTableCompanion( + id: id ?? this.id, + name: name ?? this.name, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (name.present) { + map['name'] = Variable(name.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('EquipmentTableCompanion(') + ..write('id: $id, ') + ..write('name: $name, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $ExerciseEquipmentM2NTable extends ExerciseEquipmentM2N + with TableInfo<$ExerciseEquipmentM2NTable, ExerciseEquipmentM2NData> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $ExerciseEquipmentM2NTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _exerciseIdMeta = const VerificationMeta( + 'exerciseId', + ); + @override + late final GeneratedColumn exerciseId = GeneratedColumn( + 'exercise_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES exercises_exercise (id)', + ), + ); + static const VerificationMeta _equipmentIdMeta = const VerificationMeta( + 'equipmentId', + ); + @override + late final GeneratedColumn equipmentId = GeneratedColumn( + 'equipment_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES exercises_equipment (id)', + ), + ); + @override + List get $columns => [id, exerciseId, equipmentId]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'exercises_exercise_equipment'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('exercise_id')) { + context.handle( + _exerciseIdMeta, + exerciseId.isAcceptableOrUnknown(data['exercise_id']!, _exerciseIdMeta), + ); + } else if (isInserting) { + context.missing(_exerciseIdMeta); + } + if (data.containsKey('equipment_id')) { + context.handle( + _equipmentIdMeta, + equipmentId.isAcceptableOrUnknown( + data['equipment_id']!, + _equipmentIdMeta, + ), + ); + } else if (isInserting) { + context.missing(_equipmentIdMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + ExerciseEquipmentM2NData map( + Map data, { + String? tablePrefix, + }) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return ExerciseEquipmentM2NData( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + exerciseId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}exercise_id'], + )!, + equipmentId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}equipment_id'], + )!, + ); + } + + @override + $ExerciseEquipmentM2NTable createAlias(String alias) { + return $ExerciseEquipmentM2NTable(attachedDatabase, alias); + } +} + +class ExerciseEquipmentM2NData extends DataClass implements Insertable { + final int id; + final int exerciseId; + final int equipmentId; + const ExerciseEquipmentM2NData({ + required this.id, + required this.exerciseId, + required this.equipmentId, + }); + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + map['id'] = Variable(id); + map['exercise_id'] = Variable(exerciseId); + map['equipment_id'] = Variable(equipmentId); + return map; + } + + ExerciseEquipmentM2NCompanion toCompanion(bool nullToAbsent) { + return ExerciseEquipmentM2NCompanion( + id: Value(id), + exerciseId: Value(exerciseId), + equipmentId: Value(equipmentId), + ); + } + + factory ExerciseEquipmentM2NData.fromJson( + Map json, { + ValueSerializer? serializer, + }) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return ExerciseEquipmentM2NData( + id: serializer.fromJson(json['id']), + exerciseId: serializer.fromJson(json['exerciseId']), + equipmentId: serializer.fromJson(json['equipmentId']), + ); + } + @override + Map toJson({ValueSerializer? serializer}) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return { + 'id': serializer.toJson(id), + 'exerciseId': serializer.toJson(exerciseId), + 'equipmentId': serializer.toJson(equipmentId), + }; + } + + ExerciseEquipmentM2NData copyWith({ + int? id, + int? exerciseId, + int? equipmentId, + }) => ExerciseEquipmentM2NData( + id: id ?? this.id, + exerciseId: exerciseId ?? this.exerciseId, + equipmentId: equipmentId ?? this.equipmentId, + ); + ExerciseEquipmentM2NData copyWithCompanion( + ExerciseEquipmentM2NCompanion data, + ) { + return ExerciseEquipmentM2NData( + id: data.id.present ? data.id.value : this.id, + exerciseId: data.exerciseId.present ? data.exerciseId.value : this.exerciseId, + equipmentId: data.equipmentId.present ? data.equipmentId.value : this.equipmentId, + ); + } + + @override + String toString() { + return (StringBuffer('ExerciseEquipmentM2NData(') + ..write('id: $id, ') + ..write('exerciseId: $exerciseId, ') + ..write('equipmentId: $equipmentId') + ..write(')')) + .toString(); + } + + @override + int get hashCode => Object.hash(id, exerciseId, equipmentId); + @override + bool operator ==(Object other) => + identical(this, other) || + (other is ExerciseEquipmentM2NData && + other.id == this.id && + other.exerciseId == this.exerciseId && + other.equipmentId == this.equipmentId); +} + +class ExerciseEquipmentM2NCompanion extends UpdateCompanion { + final Value id; + final Value exerciseId; + final Value equipmentId; + final Value rowid; + const ExerciseEquipmentM2NCompanion({ + this.id = const Value.absent(), + this.exerciseId = const Value.absent(), + this.equipmentId = const Value.absent(), + this.rowid = const Value.absent(), + }); + ExerciseEquipmentM2NCompanion.insert({ + required int id, + required int exerciseId, + required int equipmentId, + this.rowid = const Value.absent(), + }) : id = Value(id), + exerciseId = Value(exerciseId), + equipmentId = Value(equipmentId); + static Insertable custom({ + Expression? id, + Expression? exerciseId, + Expression? equipmentId, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (exerciseId != null) 'exercise_id': exerciseId, + if (equipmentId != null) 'equipment_id': equipmentId, + if (rowid != null) 'rowid': rowid, + }); + } + + ExerciseEquipmentM2NCompanion copyWith({ + Value? id, + Value? exerciseId, + Value? equipmentId, + Value? rowid, + }) { + return ExerciseEquipmentM2NCompanion( + id: id ?? this.id, + exerciseId: exerciseId ?? this.exerciseId, + equipmentId: equipmentId ?? this.equipmentId, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (exerciseId.present) { + map['exercise_id'] = Variable(exerciseId.value); + } + if (equipmentId.present) { + map['equipment_id'] = Variable(equipmentId.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('ExerciseEquipmentM2NCompanion(') + ..write('id: $id, ') + ..write('exerciseId: $exerciseId, ') + ..write('equipmentId: $equipmentId, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $ExerciseImageTableTable extends ExerciseImageTable + with TableInfo<$ExerciseImageTableTable, ExerciseImage> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $ExerciseImageTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _uuidMeta = const VerificationMeta('uuid'); + @override + late final GeneratedColumn uuid = GeneratedColumn( + 'uuid', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _exerciseIdMeta = const VerificationMeta( + 'exerciseId', + ); + @override + late final GeneratedColumn exerciseId = GeneratedColumn( + 'exercise_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES exercises_exercise (id)', + ), + ); + static const VerificationMeta _imageMeta = const VerificationMeta('image'); + @override + late final GeneratedColumn image = GeneratedColumn( + 'image', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _isMainMeta = const VerificationMeta('isMain'); + @override + late final GeneratedColumn isMain = GeneratedColumn( + 'is_main', + aliasedName, + false, + type: DriftSqlType.bool, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'CHECK ("is_main" IN (0, 1))', + ), + ); + static const VerificationMeta _isAiGeneratedMeta = const VerificationMeta( + 'isAiGenerated', + ); + @override + late final GeneratedColumn isAiGenerated = GeneratedColumn( + 'is_ai_generated', + aliasedName, + false, + type: DriftSqlType.bool, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'CHECK ("is_ai_generated" IN (0, 1))', + ), + ); + @override + late final GeneratedColumnWithTypeConverter style = + GeneratedColumn( + 'style', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ).withConverter($ExerciseImageTableTable.$converterstyle); + static const VerificationMeta _widthMeta = const VerificationMeta('width'); + @override + late final GeneratedColumn width = GeneratedColumn( + 'width', + aliasedName, + true, + type: DriftSqlType.int, + requiredDuringInsert: false, + ); + static const VerificationMeta _heightMeta = const VerificationMeta('height'); + @override + late final GeneratedColumn height = GeneratedColumn( + 'height', + aliasedName, + true, + type: DriftSqlType.int, + requiredDuringInsert: false, + ); + static const VerificationMeta _createdMeta = const VerificationMeta( + 'created', + ); + @override + late final GeneratedColumn created = GeneratedColumn( + 'created', + aliasedName, + false, + type: DriftSqlType.dateTime, + requiredDuringInsert: true, + ); + static const VerificationMeta _lastUpdateMeta = const VerificationMeta( + 'lastUpdate', + ); + @override + late final GeneratedColumn lastUpdate = GeneratedColumn( + 'last_update', + aliasedName, + false, + type: DriftSqlType.dateTime, + requiredDuringInsert: true, + ); + static const VerificationMeta _licenseIdMeta = const VerificationMeta( + 'licenseId', + ); + @override + late final GeneratedColumn licenseId = GeneratedColumn( + 'license_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _licenseTitleMeta = const VerificationMeta( + 'licenseTitle', + ); + @override + late final GeneratedColumn licenseTitle = GeneratedColumn( + 'license_title', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _licenseObjectUrlMeta = const VerificationMeta( + 'licenseObjectUrl', + ); + @override + late final GeneratedColumn licenseObjectUrl = GeneratedColumn( + 'license_object_url', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _licenseAuthorMeta = const VerificationMeta( + 'licenseAuthor', + ); + @override + late final GeneratedColumn licenseAuthor = GeneratedColumn( + 'license_author', + aliasedName, + true, + type: DriftSqlType.string, + requiredDuringInsert: false, + ); + static const VerificationMeta _licenseAuthorUrlMeta = const VerificationMeta( + 'licenseAuthorUrl', + ); + @override + late final GeneratedColumn licenseAuthorUrl = GeneratedColumn( + 'license_author_url', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _licenseDerivativeSourceUrlMeta = const VerificationMeta( + 'licenseDerivativeSourceUrl', + ); + @override + late final GeneratedColumn licenseDerivativeSourceUrl = GeneratedColumn( + 'license_derivative_source_url', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + @override + List get $columns => [ + id, + uuid, + exerciseId, + image, + isMain, + isAiGenerated, + style, + width, + height, + created, + lastUpdate, + licenseId, + licenseTitle, + licenseObjectUrl, + licenseAuthor, + licenseAuthorUrl, + licenseDerivativeSourceUrl, + ]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'exercises_exerciseimage'; + @override + VerificationContext validateIntegrity( + Insertable instance, { + bool isInserting = false, + }) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } else if (isInserting) { + context.missing(_idMeta); + } + if (data.containsKey('uuid')) { + context.handle( + _uuidMeta, + uuid.isAcceptableOrUnknown(data['uuid']!, _uuidMeta), + ); + } else if (isInserting) { + context.missing(_uuidMeta); + } + if (data.containsKey('exercise_id')) { + context.handle( + _exerciseIdMeta, + exerciseId.isAcceptableOrUnknown(data['exercise_id']!, _exerciseIdMeta), + ); + } else if (isInserting) { + context.missing(_exerciseIdMeta); + } + if (data.containsKey('image')) { + context.handle( + _imageMeta, + image.isAcceptableOrUnknown(data['image']!, _imageMeta), + ); + } else if (isInserting) { + context.missing(_imageMeta); + } + if (data.containsKey('is_main')) { + context.handle( + _isMainMeta, + isMain.isAcceptableOrUnknown(data['is_main']!, _isMainMeta), + ); + } else if (isInserting) { + context.missing(_isMainMeta); + } + if (data.containsKey('is_ai_generated')) { + context.handle( + _isAiGeneratedMeta, + isAiGenerated.isAcceptableOrUnknown( + data['is_ai_generated']!, + _isAiGeneratedMeta, + ), + ); + } else if (isInserting) { + context.missing(_isAiGeneratedMeta); + } + if (data.containsKey('width')) { + context.handle( + _widthMeta, + width.isAcceptableOrUnknown(data['width']!, _widthMeta), + ); + } + if (data.containsKey('height')) { + context.handle( + _heightMeta, + height.isAcceptableOrUnknown(data['height']!, _heightMeta), + ); + } + if (data.containsKey('created')) { + context.handle( + _createdMeta, + created.isAcceptableOrUnknown(data['created']!, _createdMeta), + ); + } else if (isInserting) { + context.missing(_createdMeta); + } + if (data.containsKey('last_update')) { + context.handle( + _lastUpdateMeta, + lastUpdate.isAcceptableOrUnknown(data['last_update']!, _lastUpdateMeta), + ); + } else if (isInserting) { + context.missing(_lastUpdateMeta); + } + if (data.containsKey('license_id')) { + context.handle( + _licenseIdMeta, + licenseId.isAcceptableOrUnknown(data['license_id']!, _licenseIdMeta), + ); + } else if (isInserting) { + context.missing(_licenseIdMeta); + } + if (data.containsKey('license_title')) { + context.handle( + _licenseTitleMeta, + licenseTitle.isAcceptableOrUnknown( + data['license_title']!, + _licenseTitleMeta, + ), + ); + } else if (isInserting) { + context.missing(_licenseTitleMeta); + } + if (data.containsKey('license_object_url')) { + context.handle( + _licenseObjectUrlMeta, + licenseObjectUrl.isAcceptableOrUnknown( + data['license_object_url']!, + _licenseObjectUrlMeta, + ), + ); + } else if (isInserting) { + context.missing(_licenseObjectUrlMeta); + } + if (data.containsKey('license_author')) { + context.handle( + _licenseAuthorMeta, + licenseAuthor.isAcceptableOrUnknown( + data['license_author']!, + _licenseAuthorMeta, + ), + ); + } + if (data.containsKey('license_author_url')) { + context.handle( + _licenseAuthorUrlMeta, + licenseAuthorUrl.isAcceptableOrUnknown( + data['license_author_url']!, + _licenseAuthorUrlMeta, + ), + ); + } else if (isInserting) { + context.missing(_licenseAuthorUrlMeta); + } + if (data.containsKey('license_derivative_source_url')) { + context.handle( + _licenseDerivativeSourceUrlMeta, + licenseDerivativeSourceUrl.isAcceptableOrUnknown( + data['license_derivative_source_url']!, + _licenseDerivativeSourceUrlMeta, + ), + ); + } else if (isInserting) { + context.missing(_licenseDerivativeSourceUrlMeta); + } + return context; + } + + @override + Set get $primaryKey => const {}; + @override + ExerciseImage map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return ExerciseImage( + id: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}id'], + )!, + uuid: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}uuid'], + )!, + exerciseId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}exercise_id'], + )!, + image: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}image'], + )!, + isMain: attachedDatabase.typeMapping.read( + DriftSqlType.bool, + data['${effectivePrefix}is_main'], + )!, + isAiGenerated: attachedDatabase.typeMapping.read( + DriftSqlType.bool, + data['${effectivePrefix}is_ai_generated'], + )!, + style: $ExerciseImageTableTable.$converterstyle.fromSql( + attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}style'], + )!, + ), + width: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}width'], + ), + height: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}height'], + ), + created: attachedDatabase.typeMapping.read( + DriftSqlType.dateTime, + data['${effectivePrefix}created'], + )!, + lastUpdate: attachedDatabase.typeMapping.read( + DriftSqlType.dateTime, + data['${effectivePrefix}last_update'], + )!, + licenseId: attachedDatabase.typeMapping.read( + DriftSqlType.int, + data['${effectivePrefix}license_id'], + )!, + licenseTitle: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}license_title'], + )!, + licenseObjectUrl: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}license_object_url'], + )!, + licenseAuthor: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}license_author'], + ), + licenseAuthorUrl: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}license_author_url'], + )!, + licenseDerivativeSourceUrl: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}license_derivative_source_url'], + )!, + ); + } + + @override + $ExerciseImageTableTable createAlias(String alias) { + return $ExerciseImageTableTable(attachedDatabase, alias); + } + + static TypeConverter $converterstyle = + const ExerciseImageStyleConverter(); +} + +class ExerciseImageTableCompanion extends UpdateCompanion { + final Value id; + final Value uuid; + final Value exerciseId; + final Value image; + final Value isMain; + final Value isAiGenerated; + final Value style; + final Value width; + final Value height; + final Value created; + final Value lastUpdate; + final Value licenseId; + final Value licenseTitle; + final Value licenseObjectUrl; + final Value licenseAuthor; + final Value licenseAuthorUrl; + final Value licenseDerivativeSourceUrl; + final Value rowid; + const ExerciseImageTableCompanion({ + this.id = const Value.absent(), + this.uuid = const Value.absent(), + this.exerciseId = const Value.absent(), + this.image = const Value.absent(), + this.isMain = const Value.absent(), + this.isAiGenerated = const Value.absent(), + this.style = const Value.absent(), + this.width = const Value.absent(), + this.height = const Value.absent(), + this.created = const Value.absent(), + this.lastUpdate = const Value.absent(), + this.licenseId = const Value.absent(), + this.licenseTitle = const Value.absent(), + this.licenseObjectUrl = const Value.absent(), + this.licenseAuthor = const Value.absent(), + this.licenseAuthorUrl = const Value.absent(), + this.licenseDerivativeSourceUrl = const Value.absent(), + this.rowid = const Value.absent(), + }); + ExerciseImageTableCompanion.insert({ + required int id, + required String uuid, + required int exerciseId, + required String image, + required bool isMain, + required bool isAiGenerated, + required ExerciseImageStyle style, + this.width = const Value.absent(), + this.height = const Value.absent(), + required DateTime created, + required DateTime lastUpdate, + required int licenseId, + required String licenseTitle, + required String licenseObjectUrl, + this.licenseAuthor = const Value.absent(), + required String licenseAuthorUrl, + required String licenseDerivativeSourceUrl, + this.rowid = const Value.absent(), + }) : id = Value(id), + uuid = Value(uuid), + exerciseId = Value(exerciseId), + image = Value(image), + isMain = Value(isMain), + isAiGenerated = Value(isAiGenerated), + style = Value(style), + created = Value(created), + lastUpdate = Value(lastUpdate), + licenseId = Value(licenseId), + licenseTitle = Value(licenseTitle), + licenseObjectUrl = Value(licenseObjectUrl), + licenseAuthorUrl = Value(licenseAuthorUrl), + licenseDerivativeSourceUrl = Value(licenseDerivativeSourceUrl); + static Insertable custom({ + Expression? id, + Expression? uuid, + Expression? exerciseId, + Expression? image, + Expression? isMain, + Expression? isAiGenerated, + Expression? style, + Expression? width, + Expression? height, + Expression? created, + Expression? lastUpdate, + Expression? licenseId, + Expression? licenseTitle, + Expression? licenseObjectUrl, + Expression? licenseAuthor, + Expression? licenseAuthorUrl, + Expression? licenseDerivativeSourceUrl, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (uuid != null) 'uuid': uuid, + if (exerciseId != null) 'exercise_id': exerciseId, + if (image != null) 'image': image, + if (isMain != null) 'is_main': isMain, + if (isAiGenerated != null) 'is_ai_generated': isAiGenerated, + if (style != null) 'style': style, + if (width != null) 'width': width, + if (height != null) 'height': height, + if (created != null) 'created': created, + if (lastUpdate != null) 'last_update': lastUpdate, + if (licenseId != null) 'license_id': licenseId, + if (licenseTitle != null) 'license_title': licenseTitle, + if (licenseObjectUrl != null) 'license_object_url': licenseObjectUrl, + if (licenseAuthor != null) 'license_author': licenseAuthor, + if (licenseAuthorUrl != null) 'license_author_url': licenseAuthorUrl, + if (licenseDerivativeSourceUrl != null) + 'license_derivative_source_url': licenseDerivativeSourceUrl, + if (rowid != null) 'rowid': rowid, + }); + } + + ExerciseImageTableCompanion copyWith({ + Value? id, + Value? uuid, + Value? exerciseId, + Value? image, + Value? isMain, + Value? isAiGenerated, + Value? style, + Value? width, + Value? height, + Value? created, + Value? lastUpdate, + Value? licenseId, + Value? licenseTitle, + Value? licenseObjectUrl, + Value? licenseAuthor, + Value? licenseAuthorUrl, + Value? licenseDerivativeSourceUrl, + Value? rowid, + }) { + return ExerciseImageTableCompanion( + id: id ?? this.id, + uuid: uuid ?? this.uuid, + exerciseId: exerciseId ?? this.exerciseId, + image: image ?? this.image, + isMain: isMain ?? this.isMain, + isAiGenerated: isAiGenerated ?? this.isAiGenerated, + style: style ?? this.style, + width: width ?? this.width, + height: height ?? this.height, + created: created ?? this.created, + lastUpdate: lastUpdate ?? this.lastUpdate, + licenseId: licenseId ?? this.licenseId, + licenseTitle: licenseTitle ?? this.licenseTitle, + licenseObjectUrl: licenseObjectUrl ?? this.licenseObjectUrl, + licenseAuthor: licenseAuthor ?? this.licenseAuthor, + licenseAuthorUrl: licenseAuthorUrl ?? this.licenseAuthorUrl, + licenseDerivativeSourceUrl: licenseDerivativeSourceUrl ?? this.licenseDerivativeSourceUrl, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (uuid.present) { + map['uuid'] = Variable(uuid.value); + } + if (exerciseId.present) { + map['exercise_id'] = Variable(exerciseId.value); + } + if (image.present) { + map['image'] = Variable(image.value); + } + if (isMain.present) { + map['is_main'] = Variable(isMain.value); + } + if (isAiGenerated.present) { + map['is_ai_generated'] = Variable(isAiGenerated.value); + } + if (style.present) { + map['style'] = Variable( + $ExerciseImageTableTable.$converterstyle.toSql(style.value), + ); + } + if (width.present) { + map['width'] = Variable(width.value); + } + if (height.present) { + map['height'] = Variable(height.value); + } + if (created.present) { + map['created'] = Variable(created.value); + } + if (lastUpdate.present) { + map['last_update'] = Variable(lastUpdate.value); + } + if (licenseId.present) { + map['license_id'] = Variable(licenseId.value); + } + if (licenseTitle.present) { + map['license_title'] = Variable(licenseTitle.value); + } + if (licenseObjectUrl.present) { + map['license_object_url'] = Variable(licenseObjectUrl.value); + } + if (licenseAuthor.present) { + map['license_author'] = Variable(licenseAuthor.value); + } + if (licenseAuthorUrl.present) { + map['license_author_url'] = Variable(licenseAuthorUrl.value); + } + if (licenseDerivativeSourceUrl.present) { + map['license_derivative_source_url'] = Variable( + licenseDerivativeSourceUrl.value, + ); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('ExerciseImageTableCompanion(') + ..write('id: $id, ') + ..write('uuid: $uuid, ') + ..write('exerciseId: $exerciseId, ') + ..write('image: $image, ') + ..write('isMain: $isMain, ') + ..write('isAiGenerated: $isAiGenerated, ') + ..write('style: $style, ') + ..write('width: $width, ') + ..write('height: $height, ') + ..write('created: $created, ') + ..write('lastUpdate: $lastUpdate, ') + ..write('licenseId: $licenseId, ') + ..write('licenseTitle: $licenseTitle, ') + ..write('licenseObjectUrl: $licenseObjectUrl, ') + ..write('licenseAuthor: $licenseAuthor, ') + ..write('licenseAuthorUrl: $licenseAuthorUrl, ') + ..write('licenseDerivativeSourceUrl: $licenseDerivativeSourceUrl, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $ExerciseVideoTableTable extends ExerciseVideoTable + with TableInfo<$ExerciseVideoTableTable, Video> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $ExerciseVideoTableTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _uuidMeta = const VerificationMeta('uuid'); + @override + late final GeneratedColumn uuid = GeneratedColumn( + 'uuid', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _exerciseIdMeta = const VerificationMeta( + 'exerciseId', + ); + @override + late final GeneratedColumn exerciseId = GeneratedColumn( + 'exercise_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES exercises_exercise (id)', + ), + ); + static const VerificationMeta _isMainMeta = const VerificationMeta('isMain'); + @override + late final GeneratedColumn isMain = GeneratedColumn( + 'is_main', + aliasedName, + false, + type: DriftSqlType.bool, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'CHECK ("is_main" IN (0, 1))', + ), + ); + static const VerificationMeta _urlMeta = const VerificationMeta('url'); + @override + late final GeneratedColumn url = GeneratedColumn( + 'url', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _sizeMeta = const VerificationMeta('size'); + @override + late final GeneratedColumn size = GeneratedColumn( + 'size', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _durationMeta = const VerificationMeta( + 'duration', + ); + @override + late final GeneratedColumn duration = GeneratedColumn( + 'duration', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _widthMeta = const VerificationMeta('width'); + @override + late final GeneratedColumn width = GeneratedColumn( + 'width', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _heightMeta = const VerificationMeta('height'); + @override + late final GeneratedColumn height = GeneratedColumn( + 'height', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _codecMeta = const VerificationMeta('codec'); + @override + late final GeneratedColumn codec = GeneratedColumn( + 'codec', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _codecLongMeta = const VerificationMeta( + 'codecLong', + ); + @override + late final GeneratedColumn codecLong = GeneratedColumn( + 'codec_long', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _createdMeta = const VerificationMeta( + 'created', + ); + @override + late final GeneratedColumn created = GeneratedColumn( + 'created', + aliasedName, + false, + type: DriftSqlType.dateTime, + requiredDuringInsert: true, + ); + static const VerificationMeta _lastUpdateMeta = const VerificationMeta( + 'lastUpdate', + ); + @override + late final GeneratedColumn lastUpdate = GeneratedColumn( + 'last_update', + aliasedName, + false, + type: DriftSqlType.dateTime, + requiredDuringInsert: true, + ); + static const VerificationMeta _licenseIdMeta = const VerificationMeta( + 'licenseId', + ); + @override + late final GeneratedColumn licenseId = GeneratedColumn( + 'license_id', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: true, + ); + static const VerificationMeta _licenseTitleMeta = const VerificationMeta( + 'licenseTitle', + ); + @override + late final GeneratedColumn licenseTitle = GeneratedColumn( + 'license_title', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _licenseObjectUrlMeta = const VerificationMeta( + 'licenseObjectUrl', + ); + @override + late final GeneratedColumn licenseObjectUrl = GeneratedColumn( + 'license_object_url', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _licenseAuthorMeta = const VerificationMeta( + 'licenseAuthor', + ); + @override + late final GeneratedColumn licenseAuthor = GeneratedColumn( + 'license_author', + aliasedName, + true, + type: DriftSqlType.string, + requiredDuringInsert: false, + ); + static const VerificationMeta _licenseAuthorUrlMeta = const VerificationMeta( + 'licenseAuthorUrl', + ); + @override + late final GeneratedColumn licenseAuthorUrl = GeneratedColumn( + 'license_author_url', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + static const VerificationMeta _licenseDerivativeSourceUrlMeta = const VerificationMeta( + 'licenseDerivativeSourceUrl', + ); + @override + late final GeneratedColumn licenseDerivativeSourceUrl = GeneratedColumn( + 'license_derivative_source_url', + aliasedName, + false, + type: DriftSqlType.string, + requiredDuringInsert: true, + ); + @override + List get $columns => [ + id, + uuid, + exerciseId, + isMain, + url, + size, + duration, + width, + height, + codec, + codecLong, + created, + lastUpdate, + licenseId, + licenseTitle, + licenseObjectUrl, + licenseAuthor, + licenseAuthorUrl, + licenseDerivativeSourceUrl, + ]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'exercises_exercisevideo'; + @override + VerificationContext validateIntegrity( + Insertable