diff --git a/lib/database/powersync/database.g.dart b/lib/database/powersync/database.g.dart index 30a4cd35a..b6840ede0 100644 --- a/lib/database/powersync/database.g.dart +++ b/lib/database/powersync/database.g.dart @@ -4433,6 +4433,10 @@ class $WorkoutLogTableTable extends WorkoutLogTable with TableInfo<$WorkoutLogTa DriftSqlType.int, data['${effectivePrefix}routine_id'], )!, + sessionId: attachedDatabase.typeMapping.read( + DriftSqlType.string, + data['${effectivePrefix}session_id'], + ), repetitions: attachedDatabase.typeMapping.read( DriftSqlType.double, data['${effectivePrefix}repetitions'], @@ -6733,7 +6737,7 @@ class $IngredientImageTableTable extends IngredientImageTable String get aliasedName => _alias ?? actualTableName; @override String get actualTableName => $name; - static const String $name = 'nutrition_ingredientimage'; + static const String $name = 'nutrition_image'; @override VerificationContext validateIntegrity( Insertable instance, { diff --git a/lib/database/powersync/tables/ingredient.dart b/lib/database/powersync/tables/ingredient.dart index 4906f9dba..41a6899d2 100644 --- a/lib/database/powersync/tables/ingredient.dart +++ b/lib/database/powersync/tables/ingredient.dart @@ -95,7 +95,7 @@ const PowersyncIngredientTable = ps.Table( @UseRowClass(IngredientImage) class IngredientImageTable extends Table { @override - String get tableName => 'nutrition_ingredientimage'; + String get tableName => 'nutrition_image'; IntColumn get id => integer()(); TextColumn get uuid => text()(); @@ -113,7 +113,7 @@ class IngredientImageTable extends Table { } const PowersyncIngredientImageTable = ps.Table( - 'nutrition_ingredientimage', + 'nutrition_image', [ ps.Column.text('uuid'), ps.Column.integer('ingredient_id'), diff --git a/lib/providers/ingredient_repository.dart b/lib/providers/ingredient_repository.dart index b08783387..f6431971c 100644 --- a/lib/providers/ingredient_repository.dart +++ b/lib/providers/ingredient_repository.dart @@ -20,6 +20,7 @@ * Repository for measurement entries (local Drift operations). */ +import 'package:drift/drift.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:logging/logging.dart'; import 'package:wger/models/nutrition/ingredient.dart'; @@ -37,10 +38,26 @@ class IngredientRepository { IngredientRepository(this._db); + /// Watches a single ingredient by [id], with its `image` field hydrated. + /// Emits `null` if no ingredient with that id exists, and re-emits whenever + /// either the ingredient row or its image change. Stream watchById(int id) { _logger.finer('Watching ingredient $id'); - final query = (_db.select(_db.ingredientTable)..where((t) => t.id.equals(id))); - return query.watchSingleOrNull(); + final joined = (_db.select(_db.ingredientTable)..where((t) => t.id.equals(id))).join([ + leftOuterJoin( + _db.ingredientImageTable, + _db.ingredientImageTable.ingredientId.equalsExp(_db.ingredientTable.id), + ), + ]); + + return joined.watchSingleOrNull().map((row) { + if (row == null) { + return null; + } + final ingredient = row.readTable(_db.ingredientTable); + ingredient.image = row.readTableOrNull(_db.ingredientImageTable); + return ingredient; + }); } /// Read a single ingredient by [id] once from the DB diff --git a/lib/providers/routines.g.dart b/lib/providers/routines.g.dart index edc9467a2..136e6e8a7 100644 --- a/lib/providers/routines.g.dart +++ b/lib/providers/routines.g.dart @@ -111,7 +111,7 @@ final class RoutinesRiverpodProvider RoutinesRiverpod create() => RoutinesRiverpod(); } -String _$routinesRiverpodHash() => r'e2ccfaa499f24dcd774cf6b208853b24da041318'; +String _$routinesRiverpodHash() => r'7d24f51ef42eb8599e038df510ae21fd194730fb'; abstract class _$RoutinesRiverpod extends $StreamNotifier { Stream build();