summaryrefslogtreecommitdiffstats
path: root/src/DB.cs
blob: 3555a99c2262e70458508f89c4a880747f1fc0e0 (plain) (blame)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using Microsoft.EntityFrameworkCore;

namespace BlobBin;

public sealed class DB : DbContext
{
    public DB(DbContextOptions<DB> options) : base(options) {
        Database.Migrate();
    }

    public DbSet<File> Files { get; set; }
    public DbSet<Paste> Pastes { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
        optionsBuilder.UseSqlite("data source = AppData/main.db");
        base.OnConfiguring(optionsBuilder);
    }
}

public class UploadEntityBase
{
    public UploadEntityBase() {
        Id = Guid.NewGuid();
        CreatedAt = DateTime.UtcNow;
    }

    public Guid Id { get; set; }
    public string PublicId { get; set; }
    public DateTime CreatedAt { get; set; }
    public string CreatedBy { get; set; }
    public DateTime? DeletedAt { get; set; }
    public string? PasswordHash { get; set; }
    public bool Singleton { get; set; }
    public string? AutoDeleteAfter { get; set; }
    public string? MimeType { get; set; }
}

public class File : UploadEntityBase
{
    public string? Name { get; set; }
    public long Length { get; set; }
}

public class Paste : UploadEntityBase
{
    public string? Name { get; set; }
    public string? Content { get; set; }
    public long Length { get; set; }
}