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

37 lines
1.1 KiB
C#
Raw Normal View History

2022-12-10 20:17:22 +01:00
using System.Linq.Expressions;
using Raven.Client.Documents;
2026-04-07 14:23:29 +02:00
using Finch.Media;
2022-12-10 20:17:22 +01:00
2026-04-07 14:23:29 +02:00
namespace Finch.Raven;
2022-12-10 20:17:22 +01:00
2026-04-07 14:23:29 +02:00
public class RavenMediaStoreDbProvider : IFinchMediaStoreDbProvider
2022-12-10 20:17:22 +01:00
{
protected IRavenOperations Ops { get; set; }
public RavenMediaStoreDbProvider(IRavenOperations ops)
{
Ops = ops;
}
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-10 20:17:22 +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-10 20:17:22 +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-10 20:17:22 +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-10 20:17:22 +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-10 20:17:22 +01:00
Ops.Delete(model);
}