diff options
author | vnugent <public@vaughnnugent.com> | 2023-08-28 22:00:06 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-08-28 22:00:06 -0400 |
commit | 1fe67b21fd3e0fe9e7063cd03e43e1583fce3ce1 (patch) | |
tree | ec568fa4b447a0188ced3cc01be61f0ad121ac36 /plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/DbRouteStore.cs | |
parent | 204e3a11fa8fcce549a0de2db782f0d0c20b4966 (diff) |
Patches & data-store updates
Diffstat (limited to 'plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/DbRouteStore.cs')
-rw-r--r-- | plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/DbRouteStore.cs | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/DbRouteStore.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/DbRouteStore.cs index 0c2fca6..b90ee65 100644 --- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/DbRouteStore.cs +++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/DbRouteStore.cs @@ -24,6 +24,7 @@ using System; using System.Linq; +using System.Threading; using System.Collections.Generic; using System.Threading.Tasks; @@ -31,13 +32,17 @@ using Microsoft.EntityFrameworkCore; using VNLib.Plugins.Extensions.Data; using VNLib.Plugins.Extensions.Loading.Sql; +using VNLib.Plugins.Extensions.Data.Abstractions; +using VNLib.Plugins.Extensions.Data.Extensions; namespace VNLib.Plugins.Essentials.Content.Routing.Model { - internal class DbRouteStore : DbStore<Route>, IRouteStore + internal sealed class DbRouteStore : DbStore<Route>, IRouteStore { private readonly DbContextOptions Options; + public override IDbQueryLookup<Route> QueryTable { get; } = new DbQueries(); + public DbRouteStore(PluginBase plugin) { //Load the db context options @@ -45,41 +50,42 @@ namespace VNLib.Plugins.Essentials.Content.Routing.Model } ///<inheritdoc/> - public Task GetAllRoutesAsync(ICollection<Route> routes) + public Task GetAllRoutesAsync(ICollection<Route> routes, CancellationToken cancellation) { //Get all routes as a single page from the database - return GetPageAsync(routes, 0, int.MaxValue); + return this.GetPageAsync(routes, 0, int.MaxValue, cancellation); } ///<inheritdoc/> - public override string RecordIdBuilder => Guid.NewGuid().ToString("N"); + public override string GetNewRecordId() => Guid.NewGuid().ToString("N"); ///<inheritdoc/> - protected override IQueryable<Route> GetCollectionQueryBuilder(TransactionalDbContext context, params string[] constraints) - { - string hostname = constraints[0]; - return from route in context.Set<Route>() - where route.Hostname == hostname - select route; - } + public override IDbContextHandle GetNewContext() => new RoutingContext(Options); ///<inheritdoc/> - protected override IQueryable<Route> GetSingleQueryBuilder(TransactionalDbContext context, params string[] constraints) + public override void OnRecordUpdate(Route newRecord, Route currentRecord) { - string id = constraints[0]; - return from route in context.Set<Route>() - where route.Id == id - select route; + throw new NotSupportedException(); } - ///<inheritdoc/> - public override TransactionalDbContext NewContext() => new RoutingContext(Options); - - ///<inheritdoc/> - protected override void OnRecordUpdate(Route newRecord, Route currentRecord) + private sealed record class DbQueries : IDbQueryLookup<Route> { - throw new NotSupportedException(); - } + public IQueryable<Route> GetCollectionQueryBuilder(IDbContextHandle context, params string[] constraints) + { + string hostname = constraints[0]; + return from route in context.Set<Route>() + where route.Hostname == hostname + select route; + } + public IQueryable<Route> GetSingleQueryBuilder(IDbContextHandle context, params string[] constraints) + { + + string id = constraints[0]; + return from route in context.Set<Route>() + where route.Id == id + select route; + } + } } } |