mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 10:56:31 +00:00
remove fix, todo: test
This commit is contained in:
@@ -17,6 +17,7 @@ public interface IDbFactory
|
||||
Task<T> Run<T>(Func<AnnotationsDb, Task<T>> func);
|
||||
Task Run(Func<AnnotationsDb, Task> func);
|
||||
void SaveToDisk();
|
||||
Task DeleteAnnotations(List<Annotation> annotations, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
public class DbFactory : IDbFactory
|
||||
@@ -41,7 +42,7 @@ public class DbFactory : IDbFactory
|
||||
.UseDataProvider(SQLiteTools.GetDataProvider())
|
||||
.UseConnection(_memoryConnection)
|
||||
.UseMappingSchema(AnnotationsDbSchemaHolder.MappingSchema);
|
||||
_ = _memoryDataOptions.UseTracing(TraceLevel.Info, t => logger.LogInformation(t.SqlText));
|
||||
//.UseTracing(TraceLevel.Info, t => logger.LogInformation(t.SqlText));
|
||||
|
||||
|
||||
_fileConnection = new SQLiteConnection(FileConnStr);
|
||||
@@ -96,6 +97,16 @@ public class DbFactory : IDbFactory
|
||||
{
|
||||
_memoryConnection.BackupDatabase(_fileConnection, "main", "main", -1, null, -1);
|
||||
}
|
||||
|
||||
public async Task DeleteAnnotations(List<Annotation> annotations, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var names = annotations.Select(x => x.Name).ToList();
|
||||
await Run(async db =>
|
||||
{
|
||||
await db.Detections.DeleteAsync(x => names.Contains(x.AnnotationName), token: cancellationToken);
|
||||
await db.Annotations.DeleteAsync(x => names.Contains(x.Name), token: cancellationToken);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static class AnnotationsDbSchemaHolder
|
||||
@@ -110,6 +121,7 @@ public static class AnnotationsDbSchemaHolder
|
||||
builder.Entity<Annotation>()
|
||||
.HasTableName(Constants.ANNOTATIONS_TABLENAME)
|
||||
.HasPrimaryKey(x => x.Name)
|
||||
.Ignore(x => x.Time)
|
||||
.Association(a => a.Detections, (a, d) => a.Name == d.AnnotationName);
|
||||
|
||||
builder.Entity<Detection>()
|
||||
|
||||
Reference in New Issue
Block a user