34 lines
988 B
Dart
34 lines
988 B
Dart
// Package imports:
|
||
import 'package:drift/drift.dart';
|
||
import 'package:remever/database/database.dart';
|
||
import 'package:remever/database/tables.dart';
|
||
import 'package:remever/models/collection_dto.dart';
|
||
|
||
part 'collections_dao.g.dart';
|
||
|
||
@DriftAccessor(tables: <Type>[Collections])
|
||
class CollectionsDao extends DatabaseAccessor<AppDatabase>
|
||
with _$CollectionsDaoMixin {
|
||
///
|
||
/// Репозиторий для работы с коллекциями
|
||
///
|
||
CollectionsDao(super.attachedDatabase);
|
||
|
||
/// Получение коллекций из базы данных
|
||
Stream<List<Collection>> getCollections() {
|
||
return db.managers.collections.watch();
|
||
}
|
||
|
||
/// Создание коллекции
|
||
Future<void> createCollection(CollectionDto dto) async {
|
||
await db.managers.collections.create(
|
||
(o) => o(
|
||
title: dto.title,
|
||
desc: dto.desc,
|
||
isPublic: Value<bool>(dto.isPublic),
|
||
image: Value<String?>(dto.avatar),
|
||
),
|
||
);
|
||
}
|
||
}
|