import 'package:drift/drift.dart'; import 'package:uto_manager/infrastructure/database/app_database.dart'; part 'soldier_positions_dao.g.dart'; // The Drift-generated row type for the SoldierPositions table is also named // `SoldierPosition` (same as our domain entity). We use a typedef here so the // DAO can refer to the DB row type unambiguously. typedef SoldierPositionRow = SoldierPosition; /// Data Access Object for [SoldierPositions] table operations. @DriftAccessor(tables: [SoldierPositions]) class SoldierPositionsDao extends DatabaseAccessor with _$SoldierPositionsDaoMixin { SoldierPositionsDao(super.db); /// Returns all soldier position rows. Future> getAll() => select(soldierPositions).get(); /// Returns the position with [positionId], or null if not found. Future getById(String positionId) => (select(soldierPositions)..where((t) => t.positionId.equals(positionId))).getSingleOrNull(); /// Inserts a new position row (insert-or-replace). Future upsert(SoldierPositionsCompanion entry) => into(soldierPositions).insertOnConflictUpdate(entry); /// Inserts multiple rows in a single transaction. Future upsertAll(List entries) => batch((b) => b.insertAllOnConflictUpdate(soldierPositions, entries)); /// Updates an existing position row. Future updatePosition(SoldierPositionsCompanion entry) => update(soldierPositions).replace(entry); /// Deletes the position with [positionId]. Future deletePosition(String positionId) => (delete(soldierPositions)..where((t) => t.positionId.equals(positionId))).go(); /// Returns a stream that emits all positions whenever the table changes. Stream> watchAll() => select(soldierPositions).watch(); }