import 'package:drift/drift.dart'; import 'package:uto_manager/infrastructure/database/app_database.dart'; part 'template_dao.g.dart'; /// Data Access Object for [Templates] table operations. @DriftAccessor(tables: [Templates]) class TemplateDao extends DatabaseAccessor with _$TemplateDaoMixin { TemplateDao(super.db); /// Returns all template rows. Future> getAllTemplates() => select(templates).get(); /// Returns the template with [templateId], or null if not found. Future getTemplateById(String templateId) => (select(templates)..where((t) => t.templateId.equals(templateId))).getSingleOrNull(); /// Returns all templates of the given [bctType]. Future> getByBctType(String bctType) => (select(templates)..where((t) => t.bctType.equals(bctType))).get(); /// Inserts a new template row. Future insertTemplate(TemplatesCompanion entry) => into(templates).insert(entry, mode: InsertMode.insertOrFail); /// Inserts or replaces a template row (upsert). Future upsertTemplate(TemplatesCompanion entry) => into(templates).insertOnConflictUpdate(entry); /// Updates an existing template row. Future updateTemplate(TemplatesCompanion entry) => update(templates).replace(entry); /// Deletes the template with [templateId]. Future deleteTemplate(String templateId) => (delete(templates)..where((t) => t.templateId.equals(templateId))).go(); /// Deletes all templates. Future deleteAllTemplates() => delete(templates).go(); /// Returns a stream that emits all templates whenever the table changes. Stream> watchAllTemplates() => select(templates).watch(); }