PluralKit/PluralKit.Core/Database/DatabaseExt.cs

20 lines
541 B
C#
Raw Normal View History

2020-06-13 17:36:43 +00:00
using System;
using System.Threading.Tasks;
namespace PluralKit.Core
{
public static class DatabaseExt
{
public static async Task Execute(this IDatabase db, Func<IPKConnection, Task> func)
{
await using var conn = await db.Obtain();
await func(conn);
}
public static async Task<T> Execute<T>(this IDatabase db, Func<IPKConnection, Task<T>> func)
{
await using var conn = await db.Obtain();
return await func(conn);
}
}
}