Lyo.Discord.Postgres 2.0.0

dotnet add package Lyo.Discord.Postgres --version 2.0.0
                    
NuGet\Install-Package Lyo.Discord.Postgres -Version 2.0.0
                    
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="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lyo.Discord.Postgres" Version="2.0.0" />
                    
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 2.0.0
                    
#r "nuget: Lyo.Discord.Postgres, 2.0.0"
                    
#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@2.0.0
                    
#: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=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Lyo.Discord.Postgres&version=2.0.0
                    
Install as a Cake Tool

Lyo.Discord.Postgres

PostgreSQL persistence plus Lyo.Api endpoint mappings for Discord entities. Schema name is locked to discord (PostgresDiscordOptions.Schema).

Examples

Start here

services.AddPostgresDiscordFromConfiguration(builder.Configuration);
services.AddDiscordGuildSettingsInfrastructure(); // optional, requires AddPostgresConfigStore
services.AddSingleton(new TypeAdapterConfig().ConfigureDiscordMappings());

var app = builder.Build();
app.BuildDiscordGroup();
app.Run();

What's included

  • DiscordDbContext (Database/DiscordDbContext.cs) exposes DbSets for DiscordUser, DiscordGuild, DiscordChannel, DiscordEmoji, DiscordRole, DiscordInteraction, DiscordMessage, DiscordAttachment, DiscordReaction (composite key (MessageId, ReactorId, EmojiId)), and DiscordMember (composite key (UserId, GuildId)). Find the model snapshot under Migrations/.
  • DiscordDbContextFactory for design-time tools.
  • PostgresDiscordOptions (PostgresDiscordOptions.cs). IPostgresMigrationConfig. Section "PostgresDiscord". Properties: ConnectionString, EnableAutoMigrations (default false); Schema = "discord" stays constant.
  • Helpers that map endpoints in Extensions.cs and DiscordGuildSettingsEndpoints.cs.
  • DiscordGuildSettingsHelper resolves / seeds default DiscordGuildSettings bindings.
  • DiscordGuildSettingsDefinitionSeeder. An IHostedService that registers the settings document definition with Lyo.Config.

Wire into DI (Extensions.cs)

Every registration is an IServiceCollection extension (declared inside extension(IServiceCollection services) blocks):

Method Description
AddDiscordDbContext(string connectionString) Shortcut: registers the DbContext factory plus a scoped DiscordDbContext resolved from that factory.
AddDiscordDbContextFactory(Action<PostgresDiscordOptions>) Constructs options in place.
AddDiscordDbContextFactoryFromConfiguration(config, sectionName?) Reads 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 expects the host to have already registered AddLyoQueryServices, a cache implementation, and an ILyoMapper (for example via MapsterLyoMapper configured by ConfigureDiscordMappings).

Mapster mappings (ConfigureDiscordMappings)

Call once on your TypeAdapterConfig to connect 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 ignored on request DTOs because the CRUD hooks stamp them.

Endpoint mapping (app.BuildDiscordGroup())

Maps Discord REST endpoints under group "Discord" through 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 (this entity has no audit columns).
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 invokes 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 checks the guild exists, clears Revision before save, calls NormalizeForPersistence, and returns the persisted value 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.Configuration (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.Core (transitive, lyo)
  • Lyo.Common.Json (transitive, lyo)
  • Lyo.Common.Metadata (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.Parameters (transitive, lyo)
  • Lyo.Query (transitive, lyo)
  • Lyo.Query.Evaluation (transitive, lyo)
  • Lyo.Query.Models (transitive, lyo)
  • Lyo.Result (transitive, lyo)
  • Lyo.Streams (transitive, lyo)
  • Lyo.Validation (transitive, lyo)
  • Lyo.Validation.Models (transitive, lyo)
  • BouncyCastle.Cryptography 2.6.2 (transitive, third-party, netstandard2.0)
  • DynamicExpresso.Core 2.19.3 (transitive, third-party)
  • EasyCompressor 2.1.0 (transitive, third-party)
  • Konscious.Security.Cryptography.Argon2 1.3.1 (transitive, third-party)
  • 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
2.0.0 70 9/9/2026
1.0.13 94 8/25/2026
1.0.11 101 8/23/2026
1.0.9 100 8/22/2026
1.0.6 92 8/20/2026
1.0.4 101 8/20/2026
1.0.3 92 8/19/2026
1.0.2 99 8/19/2026
1.0.1 105 8/18/2026
1.0.0 101 8/16/2026