-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate to using a db context defined in LcmCrdt instead of one provi…
…ded by Harmony
- Loading branch information
Showing
8 changed files
with
53 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Text.Json; | ||
using Crdt; | ||
using Crdt.Db; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace LcmCrdt; | ||
|
||
public class LcmCrdtDbContext(IOptions<CrdtConfig> options): DbContext, ICrdtDbContext | ||
{ | ||
public DbSet<ProjectData> ProjectData => Set<ProjectData>(); | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.UseCrdt(options.Value); | ||
|
||
modelBuilder.Entity<ProjectData>().HasKey(p => p.Id); | ||
} | ||
|
||
protected override void ConfigureConventions(ModelConfigurationBuilder builder) | ||
{ | ||
builder.Properties<MiniLcm.MultiString>() | ||
.HaveColumnType("jsonb") | ||
.HaveConversion<MultiStringDbConverter>(); | ||
builder.Properties<MiniLcm.WritingSystemId>() | ||
.HaveConversion<WritingSystemIdConverter>(); | ||
} | ||
|
||
private class MultiStringDbConverter() : ValueConverter<MiniLcm.MultiString, string>( | ||
mul => JsonSerializer.Serialize(mul, (JsonSerializerOptions?)null), | ||
json => JsonSerializer.Deserialize<MiniLcm.MultiString>(json, (JsonSerializerOptions?)null) ?? new()); | ||
|
||
private class WritingSystemIdConverter() : ValueConverter<MiniLcm.WritingSystemId, string>( | ||
id => id.Code, | ||
code => new MiniLcm.WritingSystemId(code)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters