PluralKit/PluralKit.Core/Database/Wrappers/PKTransaction.cs

31 lines
1.0 KiB
C#
Raw Normal View History

2020-06-13 16:49:05 +00:00
using System;
using System.Data;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
using Npgsql;
namespace PluralKit.Core
{
2020-06-13 17:36:43 +00:00
internal class PKTransaction: DbTransaction, IPKTransaction
2020-06-13 16:49:05 +00:00
{
public NpgsqlTransaction Inner { get; }
public PKTransaction(NpgsqlTransaction inner)
{
Inner = inner;
}
public override void Commit() => throw SyncError(nameof(Commit));
public override Task CommitAsync(CancellationToken ct = default) => Inner.CommitAsync(ct);
public override void Rollback() => throw SyncError(nameof(Rollback));
public override Task RollbackAsync(CancellationToken ct = default) => Inner.RollbackAsync(ct);
protected override DbConnection DbConnection => Inner.Connection;
public override IsolationLevel IsolationLevel => Inner.IsolationLevel;
private static Exception SyncError(string caller) => throw new Exception($"Executed synchronous IDbTransaction function {caller}!");
}
}