From 8e94a12be4a56447e78d68c37def772bef8cade4 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Tue, 15 Aug 2023 15:49:14 +1000 Subject: Convert Razor pages to Blazor --- HBContext.cs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 HBContext.cs (limited to 'HBContext.cs') diff --git a/HBContext.cs b/HBContext.cs new file mode 100644 index 0000000..17b8b3d --- /dev/null +++ b/HBContext.cs @@ -0,0 +1,41 @@ +using Microsoft.EntityFrameworkCore; +using HyperBooru.Services; + +namespace HyperBooru; + +public class HBContext : DbContext { + public DbSet Objects { get; set; } + public DbSet TagDefinitions { get; set; } + public DbSet Tags { get; set; } + public DbSet Media { get; set; } + public DbSet UploadedFiles { get; set; } + + private IConfigService config; + + public HBContext(DbContextOptions options, IConfigService config) : base(options) => + this.config = config; + + protected override void OnConfiguring(DbContextOptionsBuilder options) { + options.UseLazyLoadingProxies(); + + var path = Path.Join(config.DataPath, "HyperBooru.db"); + options.UseSqlite($"Data Source = {config.DbPath}"); + + #if DEBUG + options.EnableSensitiveDataLogging(); + #endif + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) { + modelBuilder.Entity().ToTable("Objects"); + modelBuilder.Entity().ToTable("TagDefinitions"); + modelBuilder.Entity().ToTable("Tags"); + modelBuilder.Entity().ToTable("Media"); + modelBuilder.Entity().ToTable("UploadedFiles"); + + modelBuilder.Entity().HasData(new TagDefinition[] { + new() { ObjectId = -1, Source = TagSource.Internal, Name = "nsfw" }, + new() { ObjectId = -2, Source = TagSource.Internal, Name = "ingest" } + }); + } +} \ No newline at end of file -- cgit v1.3