2020-02-12 15:16:19 +01:00
|
|
|
using System.Data.Common;
|
|
|
|
|
|
|
|
using Dapper;
|
|
|
|
|
2021-11-26 21:10:56 -05:00
|
|
|
namespace PluralKit.Core;
|
|
|
|
|
|
|
|
public static class ConnectionUtils
|
2021-08-27 11:03:47 -04:00
|
|
|
{
|
2021-11-26 21:10:56 -05:00
|
|
|
public static async IAsyncEnumerable<T> QueryStreamAsync<T>(this IPKConnection conn, string sql, object param)
|
2020-02-12 15:16:19 +01:00
|
|
|
{
|
2021-11-26 21:10:56 -05:00
|
|
|
await using var reader = (DbDataReader)await conn.ExecuteReaderAsync(sql, param);
|
|
|
|
var parser = reader.GetRowParser<T>();
|
2021-08-27 11:03:47 -04:00
|
|
|
|
2021-11-26 21:10:56 -05:00
|
|
|
while (await reader.ReadAsync())
|
|
|
|
yield return parser(reader);
|
2020-02-12 15:16:19 +01:00
|
|
|
}
|
|
|
|
}
|