improved tab & topic handling
This commit is contained in:
@@ -8,11 +8,42 @@ part 'tab.g.dart';
|
||||
class TabDao extends DatabaseAccessor<TabDatabase> with _$TabDaoMixin {
|
||||
TabDao(super.db);
|
||||
|
||||
Future<void> upsertTab(ITab tab) {
|
||||
Stream<List<TabData>> watchTabs() {
|
||||
return (db.tab.select()..orderBy([(u) => OrderingTerm.asc(u.id)])).watch();
|
||||
}
|
||||
|
||||
Stream<TabData?> watchTab(String tabId) {
|
||||
return (db.tab.select()..where((t) => t.id.equals(tabId)))
|
||||
.watchSingleOrNull();
|
||||
}
|
||||
|
||||
Stream<bool> watchTabExisiting(String tabId) {
|
||||
final existsStatement =
|
||||
existsQuery(db.tab.select()..where((t) => t.id.equals(tabId)));
|
||||
|
||||
return selectExpressions([existsStatement])
|
||||
.map((row) => row.read(existsStatement)!)
|
||||
.watchSingle();
|
||||
}
|
||||
|
||||
Stream<List<String>> watchTopicTabs(String? topicId) {
|
||||
final query = (selectOnly(db.tab)
|
||||
..addColumns([db.tab.id])
|
||||
..where(
|
||||
(topicId == null)
|
||||
? db.tab.topicId.isNull()
|
||||
: db.tab.topicId.equals(topicId),
|
||||
)
|
||||
..orderBy([OrderingTerm.asc(db.tab.id)]));
|
||||
|
||||
return query.map((row) => row.read(db.tab.id)!).watch();
|
||||
}
|
||||
|
||||
Future<void> upsertTab(ITab tab, DateTime timestamp) {
|
||||
return db.tab.insertOne(
|
||||
TabCompanion.insert(
|
||||
id: tab.id,
|
||||
timestamp: DateTime.now(),
|
||||
timestamp: timestamp,
|
||||
url: tab.url,
|
||||
topicId: Value(tab.topicId),
|
||||
title: Value(tab.title),
|
||||
@@ -24,6 +55,7 @@ class TabDao extends DatabaseAccessor<TabDatabase> with _$TabDaoMixin {
|
||||
|
||||
Future<void> updateTab(
|
||||
String id, {
|
||||
required DateTime timestamp,
|
||||
Value<Uri> url = const Value.absent(),
|
||||
Value<String?> title = const Value.absent(),
|
||||
Value<String?> topicId = const Value.absent(),
|
||||
@@ -33,7 +65,7 @@ class TabDao extends DatabaseAccessor<TabDatabase> with _$TabDaoMixin {
|
||||
|
||||
return statement.write(
|
||||
TabCompanion(
|
||||
timestamp: Value(DateTime.now()),
|
||||
timestamp: Value(timestamp),
|
||||
url: url,
|
||||
title: title,
|
||||
topicId: topicId,
|
||||
@@ -41,4 +73,18 @@ class TabDao extends DatabaseAccessor<TabDatabase> with _$TabDaoMixin {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> deleteTab(String id) {
|
||||
return db.tab.deleteOne(TabCompanion.custom(id: Variable(id)));
|
||||
}
|
||||
|
||||
Future<void> deleteTopicTabs(String? topicId) {
|
||||
return (db.tab.delete()
|
||||
..where(
|
||||
(t) => (topicId == null)
|
||||
? t.topicId.isNull()
|
||||
: t.topicId.equals(topicId),
|
||||
))
|
||||
.go();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user