Lyo.Rating.Postgres
1.0.13
dotnet add package Lyo.Rating.Postgres --version 1.0.13
NuGet\Install-Package Lyo.Rating.Postgres -Version 1.0.13
<PackageReference Include="Lyo.Rating.Postgres" Version="1.0.13" />
<PackageVersion Include="Lyo.Rating.Postgres" Version="1.0.13" />
<PackageReference Include="Lyo.Rating.Postgres" />
paket add Lyo.Rating.Postgres --version 1.0.13
#r "nuget: Lyo.Rating.Postgres, 1.0.13"
#:package Lyo.Rating.Postgres@1.0.13
#addin nuget:?package=Lyo.Rating.Postgres&version=1.0.13
#tool nuget:?package=Lyo.Rating.Postgres&version=1.0.13
Lyo.Rating.Postgres
PostgreSQL implementation of Lyo.Rating using Entity Framework Core. Persists ratings to the rating.rating table and reactions to rating.rating_reaction (PostgresRatingOptions.Schema = "rating") and ships migrations. Ratings have subject / actor (for_entity_* / from_entity_*) and an optional rating-axis Subject field (e.g. "scary", "action"). Multiple ratings per entity per user are allowed, one per subject, where subject = null is the general rating. Value is optional (a review can be text-only). Reactions (Like / Dislike) live in a sibling table. Counts are cached on the parent rating.
PostgresRatingStore implements IRatingStore and Lyo.Health.IHealth (HealthCheckName = "rating-postgres"). Registering the store also registers a liveness probe.
Examples
Usage
services.AddPostgresRatingStore(new PostgresRatingOptions {
ConnectionString = "...",
EnableAutoMigrations = true
});
Usage (2)
{
"PostgresRating": {
"ConnectionString": "Host=localhost;Database=rating;...",
"EnableAutoMigrations": true
}
}
Usage (3)
services.AddPostgresRatingStoreFromConfiguration(configuration);
Example: a user rates a movie (general + subject-specific)
await ratingStore.SaveAsync(new RatingRecord {
SubjectEntityType = "Movie",
SubjectEntityId = movieId.ToString(),
ActorEntityType = "User",
ActorEntityId = userId.ToString(),
Subject = null,
Title = "A must-see!",
Value = 4,
Message = "Great film!"
});
await ratingStore.SaveAsync(new RatingRecord {
SubjectEntityType = "Movie",
SubjectEntityId = movieId.ToString(),
ActorEntityType = "User",
ActorEntityId = userId.ToString(),
Subject = "scary",
Value = 5,
Message = "Very tense!"
});
await ratingStore.SaveAsync(new RatingRecord {
SubjectEntityType = "Movie",
SubjectEntityId = movieId.ToString(),
ActorEntityType = "User",
ActorEntityId = userId.ToString(),
Subject = "action",
Value = null,
Message = "Non-stop action, loved it."
});
Example: like / dislike a rating
var ratingRef = RatingRef.ForRating(ratingId);
var actor = EntityRef.ForGuid("User", userId);
await ratingStore.AddReactionAsync(ratingRef, actor, RatingReactionType.Like);
await ratingStore.RemoveReactionAsync(ratingRef, actor);
Migrations
export RATING_CONNECTION_STRING="Host=localhost;Database=rating;Username=postgres;Password=postgres"
dotnet ef migrations add MigrationName --project Features/Rating/Lyo.Rating.Postgres
DI extensions
AddRatingDbContextFactory(Action<PostgresRatingOptions>)/AddRatingDbContextFactory(PostgresRatingOptions)register only theIDbContextFactory<RatingDbContext>.AddRatingDbContextFactoryFromConfiguration(IConfiguration, string sectionName = PostgresRatingOptions.SectionName)same, bound from configuration (default section:PostgresRating).AddPostgresRatingStore(Action<PostgresRatingOptions>)/AddPostgresRatingStore(PostgresRatingOptions)register the DbContext factory and theIRatingStoresingleton.AddPostgresRatingStoreFromConfiguration(IConfiguration, string sectionName = PostgresRatingOptions.SectionName)register the store using configuration binding.
Usage
Or with configuration:
Entity reference
Uses Lyo.EntityReference.Models.EntityRef with generic or string-based creation:
// Generic: uses typeof(T).FullName, keys joined with ":"
var forDocket = EntityRef.For<Docket>(docketId);
var fromUser = EntityRef.For<User>(123);
var composite = EntityRef.For<Order>("ord-1", "line-2");
// String-based
var forEntity = EntityRef.ForGuid("Docket", docketGuid);
var fromEntity = EntityRef.ForKey("User", "123");
Schema
- rating.rating.
EntityRelationEntityBase:id(uuid), subject/actor columns (for_entity_type,for_entity_id,from_entity_type,from_entity_id, nullable varchar 128/256),tenant_id,context,visibility,created_at,expires_at,deleted_at,deleted_by_type,deleted_by_id,metadata(jsonb), plus rating-specificsubject(nullable),title(nullable),value(nullabledecimal),message,like_count,dislike_count, andupdated_timestamp. - rating.rating_reaction.
id(uuid); subjectfor_entity_*(always"Rating"+ parent id); actorfrom_entity_*;tenant_id(nullable uuid, inherited from the parent rating at write time),reaction_type(int;0 = Like,1 = Dislike),created_timestamp.
Tenancy
PostgresRatingStore accepts an optional Guid? tenantId on every read/write
method and resolves it through TenancyResolver under the policy configured in
PostgresRatingOptions.Tenancy (inheriting from EntityRefOptions.Mode when
unset). The rating tenant_id column is non-null, so only SingleTenantDefault
and MultiTenantStrict modes are valid. SystemOnly is rejected at store
construction. Reactions inherit the parent rating's TenantId on insert so the
reaction sub-table stays consistent with its parent. See
Lyo.EntityReference.Postgres
for the policy matrix and appsettings.json snippet.
{
"PostgresRating": {
"ConnectionString": "Host=localhost;Database=lyo;...",
"Tenancy": { "Mode": "MultiTenantStrict" }
}
}
Dependencies
Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).
Lyo.EntityReference.Models(direct, lyo)Lyo.EntityReference.Postgres(direct, lyo)Lyo.Exceptions(direct, lyo)Lyo.Health(direct, lyo)Lyo.Postgres(direct, lyo)Lyo.Rating(direct, lyo)Microsoft.EntityFrameworkCore10.0.5(direct, microsoft)Microsoft.EntityFrameworkCore.Design10.0.5(direct, microsoft)Microsoft.Extensions.Configuration.Binder10.0.5(direct, microsoft)Lyo.Common(transitive, lyo)Microsoft.EntityFrameworkCore.Relational10.0.5(transitive, microsoft)Microsoft.Extensions.DependencyInjection.Abstractions10.0.5(transitive, microsoft)Microsoft.Extensions.Hosting.Abstractions10.0.5(transitive, microsoft)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)System.Memory4.6.3(transitive, microsoft, netstandard2.0)System.Text.Json10.0.5(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.EntityReference.Models (>= 1.0.13)
- Lyo.EntityReference.Postgres (>= 1.0.13)
- Lyo.Exceptions (>= 1.0.13)
- Lyo.Health (>= 1.0.13)
- Lyo.Postgres (>= 1.0.13)
- Lyo.Rating (>= 1.0.13)
- Microsoft.EntityFrameworkCore (>= 10.0.5)
- Microsoft.Extensions.Configuration.Binder (>= 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.