|
@@ -10,53 +10,76 @@ extension EntitiesDB on FilesDB {
|
|
|
ConflictAlgorithm conflictAlgorithm = ConflictAlgorithm.replace,
|
|
|
}) async {
|
|
|
debugPrint("Inserting missing PathIDToLocalIDMapping");
|
|
|
- final db = await database;
|
|
|
- var batch = db.batch();
|
|
|
+ final db = await sqliteAsyncDB;
|
|
|
+ final parameterSets = <List<Object?>>[];
|
|
|
int batchCounter = 0;
|
|
|
for (LocalEntityData e in data) {
|
|
|
+ parameterSets.add([
|
|
|
+ e.id,
|
|
|
+ e.type.name,
|
|
|
+ e.ownerID,
|
|
|
+ e.data,
|
|
|
+ e.updatedAt,
|
|
|
+ ]);
|
|
|
+ batchCounter++;
|
|
|
+
|
|
|
if (batchCounter == 400) {
|
|
|
- await batch.commit(noResult: true);
|
|
|
- batch = db.batch();
|
|
|
+ await db.executeBatch(
|
|
|
+ '''
|
|
|
+ INSERT OR ${conflictAlgorithm.name.toUpperCase()}
|
|
|
+ INTO entities (id, type, ownerID, data, updatedAt)
|
|
|
+''',
|
|
|
+ parameterSets,
|
|
|
+ );
|
|
|
+ parameterSets.clear();
|
|
|
batchCounter = 0;
|
|
|
}
|
|
|
- batch.insert(
|
|
|
- "entities",
|
|
|
- e.toJson(),
|
|
|
- conflictAlgorithm: conflictAlgorithm,
|
|
|
- );
|
|
|
- batchCounter++;
|
|
|
}
|
|
|
- await batch.commit(noResult: true);
|
|
|
+ await db.executeBatch(
|
|
|
+ '''
|
|
|
+ INSERT OR ${conflictAlgorithm.name.toUpperCase()}
|
|
|
+ INTO entities (id, type, ownerID, data, updatedAt)
|
|
|
+''',
|
|
|
+ parameterSets,
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
Future<void> deleteEntities(
|
|
|
List<String> ids,
|
|
|
) async {
|
|
|
- final db = await database;
|
|
|
- var batch = db.batch();
|
|
|
+ final db = await sqliteAsyncDB;
|
|
|
+ final parameterSets = <List<Object?>>[];
|
|
|
int batchCounter = 0;
|
|
|
for (String id in ids) {
|
|
|
+ parameterSets.add(
|
|
|
+ [id],
|
|
|
+ );
|
|
|
+ batchCounter++;
|
|
|
+
|
|
|
if (batchCounter == 400) {
|
|
|
- await batch.commit(noResult: true);
|
|
|
- batch = db.batch();
|
|
|
+ await db.executeBatch(
|
|
|
+ '''
|
|
|
+ DELETE FROM entities WHERE id = ?
|
|
|
+ ''',
|
|
|
+ parameterSets,
|
|
|
+ );
|
|
|
+ parameterSets.clear();
|
|
|
batchCounter = 0;
|
|
|
}
|
|
|
- batch.delete(
|
|
|
- "entities",
|
|
|
- where: "id = ?",
|
|
|
- whereArgs: [id],
|
|
|
- );
|
|
|
- batchCounter++;
|
|
|
}
|
|
|
- await batch.commit(noResult: true);
|
|
|
+ await db.executeBatch(
|
|
|
+ '''
|
|
|
+ DELETE FROM entities WHERE id = ?
|
|
|
+ ''',
|
|
|
+ parameterSets,
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
Future<List<LocalEntityData>> getEntities(EntityType type) async {
|
|
|
- final db = await database;
|
|
|
- final List<Map<String, dynamic>> maps = await db.query(
|
|
|
- "entities",
|
|
|
- where: "type = ?",
|
|
|
- whereArgs: [type.typeToString()],
|
|
|
+ final db = await sqliteAsyncDB;
|
|
|
+ final List<Map<String, dynamic>> maps = await db.getAll(
|
|
|
+ 'SELECT * FROM entities WHERE type = ?',
|
|
|
+ [type.name],
|
|
|
);
|
|
|
return List.generate(maps.length, (i) {
|
|
|
return LocalEntityData.fromJson(maps[i]);
|