PluralKit/PluralKit.Core/Database/Utils/ConnectionUtils.cs

19 lines
531 B
C#
Raw Normal View History

2021-08-27 15:03:47 +00:00
using System.Collections.Generic;
using System.Data.Common;
using Dapper;
2021-08-27 15:03:47 +00:00
namespace PluralKit.Core
{
public static class ConnectionUtils
{
public static async IAsyncEnumerable<T> QueryStreamAsync<T>(this IPKConnection conn, string sql, object param)
{
2021-08-27 15:03:47 +00:00
await using var reader = (DbDataReader)await conn.ExecuteReaderAsync(sql, param);
var parser = reader.GetRowParser<T>();
2021-08-27 15:03:47 +00:00
while (await reader.ReadAsync())
2021-08-27 15:03:47 +00:00
yield return parser(reader);
}
}
}