Skip to content

Commit e1fd7ba

Browse files
author
electricessence
committed
API Improvements with test pass.
Fundamental .Excute methods are unchanged. .Retrieve, .RetrieveAsync, .Results, .ResultsAsync, .AsSourceBlockAsync, etc... Are all update to take advantage of the method's intention to the fullest.
1 parent 79c774c commit e1fd7ba

9 files changed

Lines changed: 705 additions & 310 deletions

Documentation.xml

Lines changed: 164 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ExpressiveAsyncCommandBase.cs

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,54 @@ public Task<List<T>> TakeAsync<T>(Func<IDataRecord, T> transform, int count)
126126
/// <returns>The task that completes when the iteration is done or the predicate evaluates false.</returns>
127127
public abstract Task IterateReaderAsyncWhile(Func<IDataRecord, Task<bool>> predicate);
128128

129-
/// <summary>
130-
/// Posts all transformed records to the provided target block.
131-
/// If .Complete is called on the target block, then the iteration stops.
132-
/// </summary>
133-
/// <typeparam name="T">The return type of the transform function.</typeparam>
134-
/// <param name="transform">The transform function to process each IDataRecord.</param>
135-
/// <param name="target">The target block to receive the records.</param>
136-
/// <returns>A task that is complete once there are no more results.</returns>
137-
public Task ToTargetBlockAsync<T>(ITargetBlock<T> target, Func<IDataRecord, T> transform)
129+
/// <summary>
130+
/// Asynchronously iterates all records within the first result set using an IDataReader and returns the results.
131+
/// </summary>
132+
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
133+
public abstract Task<QueryResult<Queue<object[]>>> RetrieveAsync();
134+
135+
/// <summary>
136+
/// Asynchronously iterates all records within the current result set using an IDataReader and returns the desired results.
137+
/// </summary>
138+
/// <param name="ordinals">The ordinals to request from the reader for each record.</param>
139+
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
140+
public abstract Task<QueryResult<Queue<object[]>>> RetrieveAsync(IEnumerable<int> ordinals);
141+
142+
/// <summary>
143+
/// Asynchronously iterates all records within the current result set using an IDataReader and returns the desired results.
144+
/// </summary>
145+
/// <param name="n">The first ordinal to include in the request to the reader for each record.</param>
146+
/// <param name="others">The remaining ordinals to request from the reader for each record.</param>
147+
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
148+
public Task<QueryResult<Queue<object[]>>> RetrieveAsync(int n, params int[] others)
149+
=> RetrieveAsync(new int[1] { n }.Concat(others));
150+
151+
/// <summary>
152+
/// Iterates all records within the first result set using an IDataReader and returns the desired results as a list of Dictionaries containing only the specified column values.
153+
/// </summary>
154+
/// <param name="columnNames">The column names to select.</param>
155+
/// <param name="normalizeColumnOrder">Orders the results arrays by ordinal.</param>
156+
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
157+
public abstract Task<QueryResult<Queue<object[]>>> RetrieveAsync(IEnumerable<string> columnNames, bool normalizeColumnOrder = false);
158+
159+
/// <summary>
160+
/// Iterates all records within the current result set using an IDataReader and returns the desired results.
161+
/// </summary>
162+
/// <param name="c">The first column name to include in the request to the reader for each record.</param>
163+
/// <param name="others">The remaining column names to request from the reader for each record.</param>
164+
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
165+
public Task<QueryResult<Queue<object[]>>> RetrieveAsync(string c, params string[] others)
166+
=> RetrieveAsync(new string[1] { c }.Concat(others));
167+
168+
/// <summary>
169+
/// Posts all transformed records to the provided target block.
170+
/// If .Complete is called on the target block, then the iteration stops.
171+
/// </summary>
172+
/// <typeparam name="T">The return type of the transform function.</typeparam>
173+
/// <param name="transform">The transform function to process each IDataRecord.</param>
174+
/// <param name="target">The target block to receive the records.</param>
175+
/// <returns>A task that is complete once there are no more results.</returns>
176+
public Task ToTargetBlockAsync<T>(ITargetBlock<T> target, Func<IDataRecord, T> transform)
138177
{
139178
Task<bool> lastSend = null;
140179
return IterateReaderAsyncWhile(async r =>
@@ -169,13 +208,30 @@ public ISourceBlock<T> AsSourceBlockAsync<T>(Func<IDataRecord, T> transform)
169208
public abstract ISourceBlock<T> AsSourceBlockAsync<T>(IEnumerable<KeyValuePair<string, string>> fieldMappingOverrides)
170209
where T : new();
171210

172-
173211
/// <summary>
174212
/// Asynchronously returns all records via a transform function.
175213
/// </summary>
176214
/// <param name="transform">The desired column names.</param>
177215
/// <returns>A task containing the list of results.</returns>
178-
public abstract Task<List<T>> ToListAsync<T>(Func<IDataRecord, T> transform);
216+
public async Task<List<T>> ToListAsync<T>(Func<IDataRecord, T> transform)
217+
{
218+
var results = new List<T>();
219+
await IterateReaderAsync(record => results.Add(transform(record)));
220+
return results;
221+
}
222+
223+
/// <summary>
224+
/// Asynchronously returns all records and iteratively attempts to map the fields to type T.
225+
/// </summary>
226+
/// <typeparam name="T">The model type to map the values to (using reflection).</typeparam>
227+
/// <param name="fieldMappingOverrides">An override map of field names to column names where the keys are the property names, and values are the column names.</param>
228+
/// <returns>A task containing the list of results.</returns>
229+
public async Task<IEnumerable<T>> ResultsAsync<T>(IEnumerable<KeyValuePair<string, string>> fieldMappingOverrides = null) where T : new()
230+
{
231+
var x = new Transformer<T>(fieldMappingOverrides);
232+
return x.AsDequeueingEnumerable(await RetrieveAsync(x.ColumnNames));
233+
}
234+
179235

180-
}
236+
}
181237
}

ExpressiveCommandBase.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,15 @@ public T[] ToArray<T>(Func<IDataRecord, T> transform)
399399
/// <summary>
400400
/// Iterates all records within the first result set using an IDataReader and returns the results.
401401
/// </summary>
402-
/// <returns>the DataReaderResults that contain all the results and the column mappings.</returns>
402+
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
403403
public QueryResult<Queue<object[]>> Retrieve()
404404
=> Execute(command => command.Retrieve());
405405

406406
/// <summary>
407407
/// Iterates all records within the current result set using an IDataReader and returns the desired results.
408408
/// </summary>
409409
/// <param name="ordinals">The ordinals to request from the reader for each record.</param>
410-
/// <returns>the DataReaderResults that contain all the results and the column mappings.</returns>
410+
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
411411
public QueryResult<Queue<object[]>> Retrieve(IEnumerable<int> ordinals)
412412
=> Execute(command => command.Retrieve(ordinals));
413413

@@ -416,15 +416,15 @@ public QueryResult<Queue<object[]>> Retrieve(IEnumerable<int> ordinals)
416416
/// </summary>
417417
/// <param name="n">The first ordinal to include in the request to the reader for each record.</param>
418418
/// <param name="others">The remaining ordinals to request from the reader for each record.</param>
419-
/// <returns>the DataReaderResults that contain all the results and the column mappings.</returns>
419+
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
420420
public QueryResult<Queue<object[]>> Retrieve(int n, params int[] others)
421421
=> Execute(command => command.Retrieve(n, others));
422422

423423
/// <summary>
424424
/// Iterates all records within the first result set using an IDataReader and returns the desired results as a list of Dictionaries containing only the specified column values.
425425
/// </summary>
426426
/// <param name="columnNames">The column names to select.</param>
427-
/// <returns>the DataReaderResults that contain all the results and the column mappings.</returns>
427+
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
428428
public QueryResult<Queue<object[]>> Retrieve(IEnumerable<string> columnNames)
429429
=> Execute(command => command.Retrieve(columnNames));
430430

@@ -433,7 +433,7 @@ public QueryResult<Queue<object[]>> Retrieve(IEnumerable<string> columnNames)
433433
/// </summary>
434434
/// <param name="c">The first column name to include in the request to the reader for each record.</param>
435435
/// <param name="others">The remaining column names to request from the reader for each record.</param>
436-
/// <returns>the DataReaderResults that contain all the results and the column mappings.</returns>
436+
/// <returns>The QueryResult that contains all the results and the column mappings.</returns>
437437
public QueryResult<Queue<object[]>> Retrieve(string c, params string[] others)
438438
=> Execute(command => command.Retrieve(c, others));
439439

0 commit comments

Comments
 (0)