mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-12 08:40:11 +00:00
Wrap DbTransaction too
This commit is contained in:
parent
e176ccbab5
commit
37b99f9521
6 changed files with 89 additions and 36 deletions
31
PluralKit.Core/Database/Wrappers/PKTransaction.cs
Normal file
31
PluralKit.Core/Database/Wrappers/PKTransaction.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Npgsql;
|
||||
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public class PKTransaction: DbTransaction, IPKTransaction
|
||||
{
|
||||
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}!");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue