Files
mixtape/Finch.Raven/DbProviders/RavenNumberStoreDbProvider.cs
T

41 lines
1.2 KiB
C#
Raw Normal View History

2022-12-21 00:45:41 +01:00
using Raven.Client.Documents;
using System.Linq.Expressions;
2026-04-07 14:23:29 +02:00
using Finch.Numbers;
2022-12-21 00:45:41 +01:00
2026-04-07 14:23:29 +02:00
namespace Finch.Raven;
2022-12-21 00:45:41 +01:00
2026-04-07 14:23:29 +02:00
public class RavenNumberStoreDbProvider : IFinchNumberStoreDbProvider
2022-12-21 00:45:41 +01:00
{
protected IRavenOperations Ops { get; set; }
public RavenNumberStoreDbProvider(IRavenOperations ops)
{
Ops = ops;
}
2026-04-07 14:23:29 +02:00
public Task<T> Load<T>(string id, CancellationToken ct = default) where T : FinchEntity, new() =>
2022-12-21 00:45:41 +01:00
Ops.Load<T>(id);
2026-04-07 14:23:29 +02:00
public Task<T> Find<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) where T : FinchEntity =>
2022-12-21 00:45:41 +01:00
Ops.Session.Query<T>().FirstOrDefaultAsync(expression, ct);
public async Task<IList<T>> FindAll<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default)
2026-04-07 14:23:29 +02:00
where T : FinchEntity =>
2022-12-21 00:45:41 +01:00
await Ops.Session.Query<T>().Where(expression).ToListAsync(ct);
2026-04-07 14:23:29 +02:00
public Task<Result<T>> Create<T>(T model, CancellationToken ct = default) where T : FinchEntity, new() =>
2022-12-21 00:45:41 +01:00
Ops.Create(model);
2026-04-07 14:23:29 +02:00
public Task<Result<T>> Update<T>(T model, CancellationToken ct = default) where T : FinchEntity, new() =>
2022-12-21 00:45:41 +01:00
Ops.Update(model);
2026-04-07 14:23:29 +02:00
public Task<Result<T>> Delete<T>(T model, CancellationToken ct = default) where T : FinchEntity, new() =>
2022-12-21 00:45:41 +01:00
Ops.Delete(model);
}