import 'package:drift/drift.dart';
import 'package:sendtrain/database/database.dart';

part 'sessions_dao.g.dart';

@DriftAccessor(tables: [Sessions])
class SessionsDao extends DatabaseAccessor<AppDatabase> with _$SessionsDaoMixin {
  SessionsDao(super.db);

  Future<Session> find(int id) => (select(sessions)..where((session) => session.id.equals(id) )).getSingle();
  Stream<Session> watchSession(int id) => (select(sessions)..where((session) => session.id.equals(id) )).watchSingle();
  Future<List<Session>> all() => select(sessions).get();
  Stream<List<Session>> watch() => select(sessions).watch();
  Future createOrUpdate(SessionsCompanion session) => into(sessions).insertOnConflictUpdate(session);
  Future replace(Session session) => update(sessions).replace(session);
  Future remove(Session session) => delete(sessions).delete(session);
}