1 Commits

Author SHA1 Message Date
c6f6d33fbb WIP 2025-07-15 03:26:53 +02:00

View File

@@ -0,0 +1,109 @@
import 'package:sqflite/sqflite.dart';
class LinkedListSQLExpressionGenerator<T, IDType> {
final String tableName;
final String currentItemColumnName;
final String prevItemColumnName;
final bool multilist;
final String? multilistIdentifierColumnName;
const LinkedListSQLExpressionGenerator({
required this.tableName,
required this.currentItemColumnName,
required this.prevItemColumnName,
required this.multilist,
required this.multilistIdentifierColumnName,
}) : assert(
!multilist || multilistIdentifierColumnName != null,
"Multilist expressions need to specify their list identifier column name",
);
Future<void> insertItem(
DatabaseExecutor db,
T item, {
int? position,
String? list,
}) async {
assert(
!multilist || list != null,
"`list` must be specified for multilist tables",
);
throw UnimplementedError();
}
Future<void> moveItemByPosition(
DatabaseExecutor db,
int from,
int to, {
String? list,
}) async {
assert(
!multilist || list != null,
"`list` must be specified for multilist tables",
);
throw UnimplementedError();
}
Future<void> moveItemById(
DatabaseExecutor db,
IDType id,
int to, {
String? list,
}) async {
assert(
!multilist || list != null,
"`list` must be specified for multilist tables",
);
throw UnimplementedError();
}
Future<bool> deleteItemByPosition(
DatabaseExecutor db,
int position, {
String? list,
}) async {
assert(
!multilist || list != null,
"`list` must be specified for multilist tables",
);
throw UnimplementedError();
}
Future<bool> deleteItemById(
DatabaseExecutor db,
IDType id, {
String? list,
}) async {
assert(
!multilist || list != null,
"`list` must be specified for multilist tables",
);
throw UnimplementedError();
}
/// Verify that the linked list is consistent. i.e.
/// - There are no dangling items.
/// - There are no two items with common parents.
Future<bool> verify(
DatabaseExecutor db, {
String? list,
}) async {
throw UnimplementedError();
}
/// This function tries to fix an inconsistent linked list by:
/// - Finds dangling items and appends them to the end of the list in the order they were found
/// - Finds items with common parents and straightens them out in the order they were found (as well as their tails)
Future<bool> autofix(
DatabaseExecutor db,
) async {
if (multilist) {
throw UnimplementedError("autofix is undefined for multilist tables");
}
throw UnimplementedError();
}
}