Skip to content

Commit e6c0e67

Browse files
author
Oren (electricessence)
committed
6.5.0 Release.
1 parent f583e73 commit e6c0e67

15 files changed

Lines changed: 1751 additions & 244 deletions

Channel/AsChannel.cs

Lines changed: 130 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ public static ChannelReader<T> AsChannel<T>(this IDataReader reader,
9999
return channel.Reader;
100100
}
101101

102+
/// <summary>
103+
/// Iterates an IDataReader mapping the results to classes of type <typeparamref name="T"/> and writes each record an unbound channel.
104+
/// </summary>
105+
/// <typeparam name="T">The return type of the transform function.</typeparam>
106+
/// <param name="reader">The IDataReader to iterate.</param>
107+
/// <param name="singleReader">True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur.</param>
108+
/// <param name="cancellationToken">An optional cancellation token.</param>
109+
/// <returns>The channel reader containing the results.</returns>
110+
public static ChannelReader<T> AsChannel<T>(this IDataReader reader,
111+
bool singleReader,
112+
CancellationToken cancellationToken = default)
113+
where T : new()
114+
{
115+
if (reader is null) throw new ArgumentNullException(nameof(reader));
116+
Contract.EndContractBlock();
117+
118+
var channel = CreateChannel<T>(-1, singleReader);
119+
_ = ToChannel(reader, channel.Writer, true, cancellationToken);
120+
return channel.Reader;
121+
}
122+
102123
/// <summary>
103124
/// Iterates an IDataReader mapping the results to classes of type <typeparamref name="T"/> and writes each record an unbound channel.
104125
/// </summary>
@@ -110,7 +131,7 @@ public static ChannelReader<T> AsChannel<T>(this IDataReader reader,
110131
/// <returns>The channel reader containing the results.</returns>
111132
public static ChannelReader<T> AsChannel<T>(this IDataReader reader,
112133
bool singleReader,
113-
IEnumerable<(string Field, string? Column)>? fieldMappingOverrides = null,
134+
IEnumerable<(string Field, string? Column)> fieldMappingOverrides,
114135
CancellationToken cancellationToken = default)
115136
where T : new()
116137
{
@@ -189,6 +210,27 @@ public static ChannelReader<T> AsChannel<T>(this IDbCommand command,
189210
return channel.Reader;
190211
}
191212

213+
/// <summary>
214+
/// Iterates an IDataReader mapping the results to classes of type <typeparamref name="T"/> and writes each record an unbound channel.
215+
/// </summary>
216+
/// <typeparam name="T">The return type of the transform function.</typeparam>
217+
/// <param name="command">The command to acquire a reader from to iterate.</param>
218+
/// <param name="singleReader">True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur.</param>
219+
/// <param name="cancellationToken">An optional cancellation token.</param>
220+
/// <returns>The channel reader containing the results.</returns>
221+
public static ChannelReader<T> AsChannel<T>(this IDbCommand command,
222+
bool singleReader,
223+
CancellationToken cancellationToken = default)
224+
where T : new()
225+
{
226+
if (command is null) throw new ArgumentNullException(nameof(command));
227+
Contract.EndContractBlock();
228+
229+
var channel = CreateChannel<T>(-1, singleReader);
230+
_ = ToChannel(command, channel.Writer, true, cancellationToken);
231+
return channel.Reader;
232+
}
233+
192234
/// <summary>
193235
/// Iterates an IDataReader mapping the results to classes of type <typeparamref name="T"/> and writes each record an unbound channel.
194236
/// </summary>
@@ -200,7 +242,7 @@ public static ChannelReader<T> AsChannel<T>(this IDbCommand command,
200242
/// <returns>The channel reader containing the results.</returns>
201243
public static ChannelReader<T> AsChannel<T>(this IDbCommand command,
202244
bool singleReader,
203-
IEnumerable<(string Field, string? Column)>? fieldMappingOverrides = null,
245+
IEnumerable<(string Field, string? Column)> fieldMappingOverrides,
204246
CancellationToken cancellationToken = default)
205247
where T : new()
206248
{
@@ -219,7 +261,7 @@ public static ChannelReader<T> AsChannel<T>(this IDbCommand command,
219261
/// <param name="command">The IDataReader to iterate.</param>
220262
/// <param name="singleReader">True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur.</param>
221263
/// <returns>The channel reader containing the results.</returns>
222-
public static ChannelReader<object[]> AsChannel<T>(this IExecuteReader command,
264+
public static ChannelReader<object[]> AsChannel(this IExecuteReader command,
223265
bool singleReader)
224266
{
225267
if (command is null) throw new ArgumentNullException(nameof(command));
@@ -238,7 +280,7 @@ public static ChannelReader<object[]> AsChannel<T>(this IExecuteReader command,
238280
/// <param name="singleReader">True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur.</param>
239281
/// <param name="arrayPool">The array pool to acquire buffers from.</param>
240282
/// <returns>The channel reader containing the results.</returns>
241-
public static ChannelReader<object[]> AsChannel<T>(this IExecuteReader command,
283+
public static ChannelReader<object[]> AsChannel(this IExecuteReader command,
242284
bool singleReader,
243285
ArrayPool<object> arrayPool)
244286
{
@@ -273,6 +315,25 @@ public static ChannelReader<T> AsChannel<T>(this IExecuteReader command,
273315
return channel.Reader;
274316
}
275317

318+
/// <summary>
319+
/// Iterates an IDataReader mapping the results to classes of type <typeparamref name="T"/> and writes each record an unbound channel.
320+
/// </summary>
321+
/// <typeparam name="T">The return type of the transform function.</typeparam>
322+
/// <param name="command">The IDataReader to iterate.</param>
323+
/// <param name="singleReader">True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur.</param>
324+
/// <returns>The channel reader containing the results.</returns>
325+
public static ChannelReader<T> AsChannel<T>(this IExecuteReader command,
326+
bool singleReader)
327+
where T : new()
328+
{
329+
if (command is null) throw new ArgumentNullException(nameof(command));
330+
Contract.EndContractBlock();
331+
332+
var channel = CreateChannel<T>(-1, singleReader);
333+
_ = ToChannel(command, channel.Writer, true);
334+
return channel.Reader;
335+
}
336+
276337
/// <summary>
277338
/// Iterates an IDataReader mapping the results to classes of type <typeparamref name="T"/> and writes each record an unbound channel.
278339
/// </summary>
@@ -283,7 +344,7 @@ public static ChannelReader<T> AsChannel<T>(this IExecuteReader command,
283344
/// <returns>The channel reader containing the results.</returns>
284345
public static ChannelReader<T> AsChannel<T>(this IExecuteReader command,
285346
bool singleReader,
286-
IEnumerable<(string Field, string? Column)>? fieldMappingOverrides = null)
347+
IEnumerable<(string Field, string? Column)> fieldMappingOverrides)
287348
where T : new()
288349
{
289350
if (command is null) throw new ArgumentNullException(nameof(command));
@@ -363,6 +424,27 @@ public static ChannelReader<T> AsChannelAsync<T>(this DbDataReader reader,
363424
return channel.Reader;
364425
}
365426

427+
/// <summary>
428+
/// Asynchronously iterates an DbDataReader mapping the results to classes of type <typeparamref name="T"/> and writes each record an unbound channel.
429+
/// </summary>
430+
/// <typeparam name="T">The return type of the transform function.</typeparam>
431+
/// <param name="reader">The IDataReader to iterate.</param>
432+
/// <param name="singleReader">True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur.</param>
433+
/// <param name="cancellationToken">An optional cancellation token.</param>
434+
/// <returns>The channel reader containing the results.</returns>
435+
public static ChannelReader<T> AsChannelAsync<T>(this DbDataReader reader,
436+
bool singleReader,
437+
CancellationToken cancellationToken = default)
438+
where T : new()
439+
{
440+
if (reader is null) throw new ArgumentNullException(nameof(reader));
441+
Contract.EndContractBlock();
442+
443+
var channel = CreateChannel<T>(-1, singleReader);
444+
_ = ToChannelAsync(reader, channel.Writer, true, cancellationToken);
445+
return channel.Reader;
446+
}
447+
366448
/// <summary>
367449
/// Asynchronously iterates an DbDataReader mapping the results to classes of type <typeparamref name="T"/> and writes each record an unbound channel.
368450
/// </summary>
@@ -374,7 +456,7 @@ public static ChannelReader<T> AsChannelAsync<T>(this DbDataReader reader,
374456
/// <returns>The channel reader containing the results.</returns>
375457
public static ChannelReader<T> AsChannelAsync<T>(this DbDataReader reader,
376458
bool singleReader,
377-
IEnumerable<(string Field, string? Column)>? fieldMappingOverrides = null,
459+
IEnumerable<(string Field, string? Column)> fieldMappingOverrides,
378460
CancellationToken cancellationToken = default)
379461
where T : new()
380462
{
@@ -453,6 +535,27 @@ public static ChannelReader<T> AsChannelAsync<T>(this DbCommand command,
453535
return channel.Reader;
454536
}
455537

538+
/// <summary>
539+
/// Asynchronously iterates an DbDataReader mapping the results to classes of type <typeparamref name="T"/> and writes each record an unbound channel.
540+
/// </summary>
541+
/// <typeparam name="T">The return type of the transform function.</typeparam>
542+
/// <param name="command">The command to acquire a reader from to iterate.</param>
543+
/// <param name="singleReader">True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur.</param>
544+
/// <param name="cancellationToken">An optional cancellation token.</param>
545+
/// <returns>The channel reader containing the results.</returns>
546+
public static ChannelReader<T> AsChannelAsync<T>(this DbCommand command,
547+
bool singleReader,
548+
CancellationToken cancellationToken = default)
549+
where T : new()
550+
{
551+
if (command is null) throw new ArgumentNullException(nameof(command));
552+
Contract.EndContractBlock();
553+
554+
var channel = CreateChannel<T>(-1, singleReader);
555+
_ = ToChannelAsync(command, channel.Writer, true, cancellationToken);
556+
return channel.Reader;
557+
}
558+
456559
/// <summary>
457560
/// Asynchronously iterates an DbDataReader mapping the results to classes of type <typeparamref name="T"/> and writes each record an unbound channel.
458561
/// </summary>
@@ -464,7 +567,7 @@ public static ChannelReader<T> AsChannelAsync<T>(this DbCommand command,
464567
/// <returns>The channel reader containing the results.</returns>
465568
public static ChannelReader<T> AsChannelAsync<T>(this DbCommand command,
466569
bool singleReader,
467-
IEnumerable<(string Field, string? Column)>? fieldMappingOverrides = null,
570+
IEnumerable<(string Field, string? Column)> fieldMappingOverrides,
468571
CancellationToken cancellationToken = default)
469572
where T : new()
470573
{
@@ -536,6 +639,25 @@ public static ChannelReader<T> AsChannelAsync<T>(this IExecuteReaderAsync comman
536639
return channel.Reader;
537640
}
538641

642+
/// <summary>
643+
/// Asynchronously iterates an DbDataReader mapping the results to classes of type <typeparamref name="T"/> and writes each record an unbound channel.
644+
/// </summary>
645+
/// <typeparam name="T">The return type of the transform function.</typeparam>
646+
/// <param name="command">The IDataReader to iterate.</param>
647+
/// <param name="singleReader">True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur.</param>
648+
/// <returns>The channel reader containing the results.</returns>
649+
public static ChannelReader<T> AsChannelAsync<T>(this IExecuteReaderAsync command,
650+
bool singleReader)
651+
where T : new()
652+
{
653+
if (command is null) throw new ArgumentNullException(nameof(command));
654+
Contract.EndContractBlock();
655+
656+
var channel = CreateChannel<T>(-1, singleReader);
657+
_ = ToChannelAsync(command, channel.Writer, true);
658+
return channel.Reader;
659+
}
660+
539661
/// <summary>
540662
/// Asynchronously iterates an DbDataReader mapping the results to classes of type <typeparamref name="T"/> and writes each record an unbound channel.
541663
/// </summary>
@@ -546,7 +668,7 @@ public static ChannelReader<T> AsChannelAsync<T>(this IExecuteReaderAsync comman
546668
/// <returns>The channel reader containing the results.</returns>
547669
public static ChannelReader<T> AsChannelAsync<T>(this IExecuteReaderAsync command,
548670
bool singleReader,
549-
IEnumerable<(string Field, string? Column)>? fieldMappingOverrides = null)
671+
IEnumerable<(string Field, string? Column)> fieldMappingOverrides)
550672
where T : new()
551673
{
552674
if (command is null) throw new ArgumentNullException(nameof(command));

0 commit comments

Comments
 (0)