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

part 'object_media_items_dao.g.dart';

@DriftAccessor(tables: [ObjectMediaItems])
class ObjectMediaItemsDao extends DatabaseAccessor<AppDatabase> with _$ObjectMediaItemsDaoMixin {
  ObjectMediaItemsDao(super.db);

  Future createOrUpdate(ObjectMediaItemsCompanion objectMediaItem) => into(objectMediaItems).insertOnConflictUpdate(objectMediaItem);

  Future<List<ObjectMediaItem>> all() async {
    return await select(objectMediaItems).get();
  }

  Future<ObjectMediaItem> find(int id) async {
    return await (select(objectMediaItems)..where((objectMediaItem) => objectMediaItem.id.equals(id) )).getSingle();
  }
}
