summaryrefslogtreecommitdiff
path: root/HyperBooruContext.cs
blob: fecbc4cdfba0740047b2393484837e6caa4929cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Microsoft.EntityFrameworkCore;
using System.Text.Json;

namespace HyperBooru;

public class HyperBooruDbContext : DbContext {
    public DbSet<DbObject>        Objects        { get; set; }
    public DbSet<DbTagDefinition> TagDefinitions { get; set; }
    public DbSet<DbTag>           Tags           { get; set; }
    public DbSet<DbMedia>         Media          { get; set; }
    public DbSet<DbUploadedFile>  UploadedFiles  { get; set; }

    private IConfigService config;

    public HyperBooruDbContext(IConfigService config) =>
        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}");
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder) {
        modelBuilder.Entity<DbObject>().ToTable("Objects");
        modelBuilder.Entity<DbTagDefinition>().ToTable("TagDefinitions");
        modelBuilder.Entity<DbTag>().ToTable("Tags");
        modelBuilder.Entity<DbMedia>().ToTable("Media");
        modelBuilder.Entity<DbUploadedFile>().ToTable("UploadedFiles");
    }
}