|
|
@@ -393,10 +393,12 @@ class FileProcess {
|
|
|
.inFilter(scopeName, e)
|
|
|
.limit(100000);
|
|
|
|
|
|
- oldIds.addAll(res.map((e) => filterMapByKeys(e, ["id"])).toList());
|
|
|
- oldComparable.addAll(res
|
|
|
- .map((e) => filterMapByKeys(e, _headers[filename] ?? []))
|
|
|
- .toList());
|
|
|
+ // oldIds.addAll(res.map((e) => filterMapByKeys(e, ["id"])).toList());
|
|
|
+ // oldComparable.addAll(res
|
|
|
+ // .map((e) => filterMapByKeys(e, _headers[filename] ?? []))
|
|
|
+ // .toList());
|
|
|
+ oldIds.addAll(res.map((e) => {"id": e["id"]}));
|
|
|
+ oldComparable.addAll(res.map((e) => e..remove("id")));
|
|
|
}
|
|
|
|
|
|
List<int> indexToRemove = [];
|
|
|
@@ -429,25 +431,47 @@ class FileProcess {
|
|
|
indexToRemove.add(i);
|
|
|
}
|
|
|
}
|
|
|
+ try {
|
|
|
+ // removing index to remove with id
|
|
|
+ for (var e in splitList(
|
|
|
+ indexToRemove.map((e) => oldIds[e]['id']).toList(),
|
|
|
+ headerToNb(indexToRemove.map((e) => oldIds[e]['id']).toList()))) {
|
|
|
+ await supabase
|
|
|
+ .from(tables[filename]!) // Replace with your actual table name
|
|
|
+ .delete()
|
|
|
+ .inFilter('id', e);
|
|
|
+ }
|
|
|
|
|
|
- // removing index to remove with id
|
|
|
- for (var e in splitList(indexToRemove.map((e) => oldIds[e]['id']).toList(),
|
|
|
- headerToNb(indexToRemove.map((e) => oldIds[e]['id']).toList()))) {
|
|
|
+ // insering new data
|
|
|
await supabase
|
|
|
.from(tables[filename]!) // Replace with your actual table name
|
|
|
- .delete()
|
|
|
- .inFilter('id', e);
|
|
|
+ .insert(mapsToInsert);
|
|
|
+ } catch (e, stackTrace) {
|
|
|
+ print('Error: $e\n$stackTrace');
|
|
|
}
|
|
|
-
|
|
|
- // insering new data
|
|
|
- await supabase
|
|
|
- .from(tables[filename]!) // Replace with your actual table name
|
|
|
- .insert(mapsToInsert);
|
|
|
-
|
|
|
print(
|
|
|
" insert:${mapsToInsert.length} remove:${indexToRemove.length} maintain:${indexToMaintain.length}");
|
|
|
}
|
|
|
|
|
|
+ bool mapEquals<T, U>(Map<T, U>? a, Map<T, U>? b) {
|
|
|
+ if (a == null) {
|
|
|
+ return b == null;
|
|
|
+ }
|
|
|
+ if (b == null || a.length != b.length) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (identical(a, b)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ for (final T key in a.keys) {
|
|
|
+ if (!b.containsKey(key) || b[key] != a[key]) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+/*
|
|
|
bool mapEquals(Map<String, dynamic> map1, Map<String, dynamic> map2) {
|
|
|
//if (map1.length != map2.length) return false;
|
|
|
for (var key in map1.keys) {
|
|
|
@@ -455,7 +479,7 @@ class FileProcess {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+*/
|
|
|
int findIndex(List<dynamic> list, dynamic element) {
|
|
|
for (int i = 0; i < list.length; i++) {
|
|
|
if (mapEquals(list[i], element)) {
|