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