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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lyo.Discord.Postgres" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lyo.Discord.Postgres" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Lyo.Discord.Postgres" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Lyo.Discord.Postgres --version 1.0.1
                    
#r "nuget: Lyo.Discord.Postgres, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Lyo.Discord.Postgres@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Lyo.Discord.Postgres&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Lyo.Discord.Postgres&version=1.0.1
                    
Install as a Cake Tool

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) with DbSets for DiscordUser, DiscordGuild, DiscordChannel, DiscordEmoji, DiscordRole, DiscordInteraction, DiscordMessage, DiscordAttachment, DiscordReaction (composite key (MessageId, ReactorId, EmojiId)), and DiscordMember (composite key (UserId, GuildId)). The model snapshot lives under Migrations/.
  • DiscordDbContextFactory for design-time tooling.
  • PostgresDiscordOptions (PostgresDiscordOptions.cs) — IPostgresMigrationConfig. Section "PostgresDiscord". Properties: ConnectionString, EnableAutoMigrations (default false); Schema = "discord" is constant.
  • Endpoint mapping helpers in Extensions.cs and DiscordGuildSettingsEndpoints.cs.
  • DiscordGuildSettingsHelper for resolving / seeding default DiscordGuildSettings bindings.
  • DiscordGuildSettingsDefinitionSeederIHostedService that registers the settings document definition with Lyo.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)
  • Mapster 10.0.10 — (direct, third-party)
  • Microsoft.EntityFrameworkCore 10.0.5 — (direct, microsoft)
  • Microsoft.EntityFrameworkCore.Design 10.0.5 — (direct, microsoft)
  • Microsoft.Extensions.Configuration.Binder 10.0.5 — (direct, microsoft)
  • Microsoft.Extensions.Hosting.Abstractions 10.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.Cryptography 2.6.2 — (transitive, third-party, netstandard2.0)
  • EasyCompressor 2.1.0 — (transitive, third-party)
  • Konscious.Security.Cryptography.Argon2 1.3.1 — (transitive, third-party)
  • Microsoft.AspNetCore.Authorization 10.0.5 — (transitive, microsoft)
  • Microsoft.AspNetCore.Http.Abstractions 2.* — (transitive, microsoft)
  • Microsoft.AspNetCore.OpenApi 10.0.5 — (transitive, microsoft)
  • Microsoft.Bcl.AsyncInterfaces 10.0.5 — (transitive, microsoft, netstandard2.0)
  • Microsoft.EntityFrameworkCore.Analyzers 10.0.5 — (transitive, microsoft)
  • Microsoft.EntityFrameworkCore.Relational 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.Caching.Memory 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.DependencyInjection 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.DependencyInjection.Abstractions 10.0.5 — (transitive, microsoft, net10.0, netstandard2.0)
  • Microsoft.Extensions.Logging.Abstractions 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.Options 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.Options.ConfigurationExtensions 10.0.5 — (transitive, microsoft)
  • Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3 — (transitive, third-party)
  • SmartFormat.NET 3.6.1 — (transitive, third-party)
  • System.Buffers 4.6.1 — (transitive, microsoft, netstandard2.0)
  • System.ComponentModel.Annotations 5.0.0 — (transitive, microsoft)
  • System.IO.Hashing 10.0.5 — (transitive, microsoft, net10.0)
  • System.Memory 4.6.3 — (transitive, microsoft, netstandard2.0)
  • System.Text.Json 10.0.5 — (transitive, microsoft, netstandard2.0)
  • System.Threading.Tasks.Extensions 4.6.3 — (transitive, microsoft, netstandard2.0)
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 30 8/18/2026
1.0.0 54 8/16/2026