Compare commits
1 Commits
datasource
...
linked-lis
| Author | SHA1 | Date | |
|---|---|---|---|
|
c6f6d33fbb
|
109
lib/database/linked_list.dart
Normal file
109
lib/database/linked_list.dart
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user