Lyo.Discord.Postgres
1.0.1
dotnet add package Lyo.Discord.Postgres --version 1.0.1
NuGet\Install-Package Lyo.Discord.Postgres -Version 1.0.1
<PackageReference Include="Lyo.Discord.Postgres" Version="1.0.1" />
<PackageVersion Include="Lyo.Discord.Postgres" Version="1.0.1" />
<PackageReference Include="Lyo.Discord.Postgres" />
paket add Lyo.Discord.Postgres --version 1.0.1
#r "nuget: Lyo.Discord.Postgres, 1.0.1"
#:package Lyo.Discord.Postgres@1.0.1
#addin nuget:?package=Lyo.Discord.Postgres&version=1.0.1
#tool nuget:?package=Lyo.Discord.Postgres&version=1.0.1
Lyo.Discord.Postgres
PostgreSQL persistence and Lyo.Api endpoint mappings for Discord entities. Schema name is fixed to discord (PostgresDiscordOptions.Schema).
Examples
Quick start
services.AddPostgresDiscordFromConfiguration(builder.Configuration);
services.AddDiscordGuildSettingsInfrastructure(); // optional, requires AddPostgresConfigStore
services.AddSingleton(new TypeAdapterConfig().ConfigureDiscordMappings());
var app = builder.Build();
app.BuildDiscordGroup();
app.Run();
What ships
DiscordDbContext(Database/DiscordDbContext.cs) withDbSets forDiscordUser,DiscordGuild,DiscordChannel,DiscordEmoji,DiscordRole,DiscordInteraction,DiscordMessage,DiscordAttachment,DiscordReaction(composite key(MessageId, ReactorId, EmojiId)), andDiscordMember(composite key(UserId, GuildId)). The model snapshot lives underMigrations/.DiscordDbContextFactoryfor design-time tooling.PostgresDiscordOptions(PostgresDiscordOptions.cs) —IPostgresMigrationConfig. Section"PostgresDiscord". Properties:ConnectionString,EnableAutoMigrations(defaultfalse);Schema = "discord"is constant.- Endpoint mapping helpers in
Extensions.csandDiscordGuildSettingsEndpoints.cs. DiscordGuildSettingsHelperfor resolving / seeding defaultDiscordGuildSettingsbindings.DiscordGuildSettingsDefinitionSeeder—IHostedServicethat registers the settings document definition withLyo.Config.
DI surface (Extensions.cs)
All registrations are extension methods on IServiceCollection (declared inside extension(IServiceCollection services) blocks):
| Method | Description |
|---|---|
AddDiscordDbContext(string connectionString) |
Convenience: registers the DbContext factory plus a scoped DiscordDbContext resolved from the factory. |
AddDiscordDbContext(Action<DbContextOptionsBuilder>) |
Standard EF AddDbContext overload. |
AddDiscordDbContextFactory(Action<PostgresDiscordOptions>) |
Builds options inline. |
AddDiscordDbContextFactoryFromConfiguration(config, sectionName?) |
Binds options from the supplied configuration (default section "PostgresDiscord"). |
AddDiscordDbContextFactory(PostgresDiscordOptions) |
Registers the factory and Npgsql provider, points the migrations history table at the discord schema, and wires AddPostgresMigrations<DiscordDbContext, …>. |
AddPostgresDiscord(...) (3 overloads) |
The factory method above plus AddLyoCrudServices<DiscordDbContext>(). Use this when hosting the Discord REST API. |
AddDiscordGuildSettingsInfrastructure() |
Registers the hosted seeder so Lyo.Config knows about DiscordGuildSettings (requires AddPostgresConfigStore). |
AddPostgresDiscord requires that the host has already registered AddLyoQueryServices, a cache implementation, and an ILyoMapper (e.g. via MapsterLyoMapper configured by
ConfigureDiscordMappings).
Mapster mappings — ConfigureDiscordMappings
Call once on your TypeAdapterConfig to wire the *Req ↔ EF ↔ *Res mappings used by Lyo.Api CRUD. Two name-sanitizers run for nullable input: DiscordUsernameOrPlaceholder (≤ 35 chars, falls back to "(unknown)") and DiscordGuildNameOrPlaceholder (≤ 50 chars). Audit timestamps (CreatedTimestamp, UpdatedTimestamp) are explicitly ignored from request DTOs because the CRUD hooks set them.
Endpoint mapping — app.BuildDiscordGroup()
Maps the full Discord REST surface under group "Discord" using the typed CreateBuilder pipeline. Each entity gets ApiFeatureFlag.All | UpsertInheritCreate | UpsertInheritUpdate | PatchInheritsUpdate plus a CrudConfiguration<DiscordDbContext, T, TReq> that stamps CreatedTimestamp / UpdatedTimestamp in BeforeCreate /
BeforeUpdate:
| Route segment | EF entity | Notes |
|---|---|---|
Discord/User |
DiscordUser |
Audit hook only. |
Discord/Guild |
DiscordGuild |
Audit hook and AfterUpsert that calls DiscordGuildSettingsHelper.EnsureDefaultBindingAsync if IConfigStore is registered. |
Discord/Channel |
DiscordChannel |
Audit hook only. |
Discord/Emoji |
DiscordEmoji |
Audit hook only. |
Discord/Role |
DiscordRole |
Audit hook only. |
Discord/Interaction |
DiscordInteraction |
Default config (no audit columns on this entity). |
Discord/Message |
DiscordMessage |
Audit hook only. |
Discord/Attachment |
DiscordAttachment |
Default config. |
Discord/Member |
DiscordMember |
Composite PK (UserId, GuildId) → only Query, Upsert/UpsertBulk, Patch/PatchBulk (no GET-by-id). |
BuildDiscordGroup also calls MapDiscordGuildSettingsEndpoints, which (only when an IConfigStore is registered) maps:
| Method | Route |
|---|---|
GET |
Discord/Guild/{guildId:long}/GuildSettings |
PUT |
Discord/Guild/{guildId:long}/GuildSettings |
GET |
Discord/Guild/{guildId:long}/GuildSettings/Revisions |
POST |
Discord/Guild/{guildId:long}/GuildSettings/Revert/{revision:int} |
The PUT route validates the guild exists, clears Revision before save, calls NormalizeForPersistence, and round-trips the persisted value back to the caller. The host is
expected to layer authorization on top — no auth is wired here by default.
Dependencies
Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).
Lyo.Api— (direct, lyo)Lyo.Config— (direct, lyo)Lyo.Discord.Models— (direct, lyo)Lyo.EntityReference.Models— (direct, lyo)Lyo.Exceptions— (direct, lyo)Lyo.Postgres— (direct, lyo)Mapster10.0.10— (direct, third-party)Microsoft.EntityFrameworkCore10.0.5— (direct, microsoft)Microsoft.EntityFrameworkCore.Design10.0.5— (direct, microsoft)Microsoft.Extensions.Configuration.Binder10.0.5— (direct, microsoft)Microsoft.Extensions.Hosting.Abstractions10.0.5— (direct, microsoft)Lyo.Api.Models— (transitive, lyo)Lyo.Cache— (transitive, lyo)Lyo.Common— (transitive, lyo)Lyo.Compression— (transitive, lyo)Lyo.DateAndTime— (transitive, lyo)Lyo.Diagnostic— (transitive, lyo)Lyo.Diagnostic.AspNetCore— (transitive, lyo)Lyo.Diff— (transitive, lyo)Lyo.Encryption— (transitive, lyo)Lyo.Formatter— (transitive, lyo)Lyo.Hashing— (transitive, lyo)Lyo.Health— (transitive, lyo)Lyo.KeyStore— (transitive, lyo)Lyo.Metrics— (transitive, lyo)Lyo.PackageMetadata— (transitive, lyo)Lyo.Query— (transitive, lyo)Lyo.Query.Models— (transitive, lyo)Lyo.Result— (transitive, lyo)Lyo.Streams— (transitive, lyo)Lyo.Validation— (transitive, lyo)BouncyCastle.Cryptography2.6.2— (transitive, third-party, netstandard2.0)EasyCompressor2.1.0— (transitive, third-party)Konscious.Security.Cryptography.Argon21.3.1— (transitive, third-party)Microsoft.AspNetCore.Authorization10.0.5— (transitive, microsoft)Microsoft.AspNetCore.Http.Abstractions2.*— (transitive, microsoft)Microsoft.AspNetCore.OpenApi10.0.5— (transitive, microsoft)Microsoft.Bcl.AsyncInterfaces10.0.5— (transitive, microsoft, netstandard2.0)Microsoft.EntityFrameworkCore.Analyzers10.0.5— (transitive, microsoft)Microsoft.EntityFrameworkCore.Relational10.0.5— (transitive, microsoft)Microsoft.Extensions.Caching.Memory10.0.5— (transitive, microsoft)Microsoft.Extensions.DependencyInjection10.0.5— (transitive, microsoft)Microsoft.Extensions.DependencyInjection.Abstractions10.0.5— (transitive, microsoft, net10.0, netstandard2.0)Microsoft.Extensions.Logging.Abstractions10.0.5— (transitive, microsoft)Microsoft.Extensions.Options10.0.5— (transitive, microsoft)Microsoft.Extensions.Options.ConfigurationExtensions10.0.5— (transitive, microsoft)Npgsql.EntityFrameworkCore.PostgreSQL10.0.3— (transitive, third-party)SmartFormat.NET3.6.1— (transitive, third-party)System.Buffers4.6.1— (transitive, microsoft, netstandard2.0)System.ComponentModel.Annotations5.0.0— (transitive, microsoft)System.IO.Hashing10.0.5— (transitive, microsoft, net10.0)System.Memory4.6.3— (transitive, microsoft, netstandard2.0)System.Text.Json10.0.5— (transitive, microsoft, netstandard2.0)System.Threading.Tasks.Extensions4.6.3— (transitive, microsoft, netstandard2.0)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Lyo.Api (>= 1.0.1)
- Lyo.Config (>= 1.0.1)
- Lyo.Discord.Models (>= 1.0.1)
- Lyo.EntityReference.Models (>= 1.0.1)
- Lyo.Exceptions (>= 1.0.1)
- Lyo.Postgres (>= 1.0.1)
- Mapster (>= 10.0.10)
- Microsoft.EntityFrameworkCore (>= 10.0.5)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.5)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.