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