mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 08:26:30 +00:00
55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using LinqToDB;
|
|
using LinqToDB.Mapping;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Azaion.Common.Database;
|
|
|
|
public static class AnnotationsDbSchemaHolder
|
|
{
|
|
public static readonly MappingSchema MappingSchema;
|
|
|
|
static AnnotationsDbSchemaHolder()
|
|
{
|
|
MappingSchema = new MappingSchema();
|
|
var builder = new FluentMappingBuilder(MappingSchema);
|
|
|
|
var annotationBuilder = builder.Entity<Annotation>();
|
|
annotationBuilder.HasTableName(Constants.ANNOTATIONS_TABLENAME)
|
|
.HasPrimaryKey(x => x.Name)
|
|
.Association(a => a.Detections, (a, d) => a.Name == d.AnnotationName)
|
|
.Property(x => x.Time)
|
|
.HasDataType(DataType.Int64)
|
|
.HasConversion(ts => ts.Ticks, t => new TimeSpan(t));
|
|
|
|
annotationBuilder
|
|
.Ignore(x => x.Milliseconds)
|
|
.Ignore(x => x.Classes)
|
|
.Ignore(x => x.ImagePath)
|
|
.Ignore(x => x.LabelPath)
|
|
.Ignore(x => x.ThumbPath)
|
|
.Ignore(x => x.ClassName)
|
|
.Ignore(x => x.Colors)
|
|
.Ignore(x => x.SplitTile)
|
|
.Ignore(x => x.IsSplit)
|
|
.Ignore(x => x.TimeStr);
|
|
|
|
builder.Entity<Detection>()
|
|
.HasTableName(Constants.DETECTIONS_TABLENAME);
|
|
|
|
builder.Entity<AnnotationQueueRecord>()
|
|
.HasTableName(Constants.ANNOTATIONS_QUEUE_TABLENAME)
|
|
.HasPrimaryKey(x => x.Id)
|
|
.Property(x => x.AnnotationNames)
|
|
.HasDataType(DataType.NVarChar)
|
|
.HasConversion(list => JsonConvert.SerializeObject(list), str => JsonConvert.DeserializeObject<List<string>>(str) ?? new List<string>());
|
|
|
|
builder.Entity<MediaFile>()
|
|
.HasTableName(Constants.MEDIAFILE_TABLENAME)
|
|
.HasPrimaryKey(x => x.Hash)
|
|
.Association(a => a.Annotations, (mf, a) =>
|
|
mf.Name == a.OriginalMediaName ||
|
|
mf.Hash == a.MediaHash);
|
|
|
|
builder.Build();
|
|
}
|
|
} |