2020-02-12 14:16:19 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data.Common;
|
|
|
|
|
|
|
|
|
|
using Dapper;
|
|
|
|
|
|
|
|
|
|
namespace PluralKit.Core {
|
|
|
|
|
public static class ConnectionUtils
|
|
|
|
|
{
|
2020-06-13 17:36:43 +00:00
|
|
|
|
public static async IAsyncEnumerable<T> QueryStreamAsync<T>(this IDatabase connFactory, string sql, object param)
|
2020-02-12 14:16:19 +00:00
|
|
|
|
{
|
2020-06-13 16:31:20 +00:00
|
|
|
|
await using var conn = await connFactory.Obtain();
|
2020-02-12 14:16:19 +00:00
|
|
|
|
|
|
|
|
|
await using var reader = (DbDataReader) await conn.ExecuteReaderAsync(sql, param);
|
|
|
|
|
var parser = reader.GetRowParser<T>();
|
2020-06-13 16:31:20 +00:00
|
|
|
|
while (await reader.ReadAsync())
|
2020-02-12 14:16:19 +00:00
|
|
|
|
yield return parser(reader);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
await using var reader = (DbDataReader) await conn.ExecuteReaderAsync(sql, param);
|
|
|
|
|
var parser = reader.GetRowParser<T>();
|
2020-06-13 16:31:20 +00:00
|
|
|
|
while (await reader.ReadAsync())
|
2020-02-12 14:16:19 +00:00
|
|
|
|
yield return parser(reader);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|