/
ISqlExecutorAsync.cs
143 lines (139 loc) · 12.2 KB
/
ISqlExecutorAsync.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#region Licenses
/*MIT License
Copyright(c) 2020
Robert Garrison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.*/
#endregion
#region Using Statements
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace ADO.Net.Client.Core
{
/// <summary>
/// Contract class that defines asynchronous operations against a database
/// </summary>
public interface ISqlExecutorAsync
{
#region Data Retrieval
#if !NET45
/// <summary>
/// Utility method for returning an <see cref="IEnumerable{T}"/> of scalar values from the database
/// </summary>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <param name="commandTimeout">The wait time in seconds before terminating the attempt to execute a command and generating an error</param>
/// <param name="parameters">The parameters associated with a database query</param>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="queryCommandType">Represents how a command should be interpreted by the data provider</param>
/// <typeparam name="T">The data type to return from data value returned from the query</typeparam>
/// <returns>Returns an <see cref="IEnumerable{T}"/> of the value of the first column in the result set as an instance of <typeparamref name="T"/></returns>
IAsyncEnumerable<T> GetScalarValuesStreamAsync<T>(string query, CommandType queryCommandType, IEnumerable<DbParameter> parameters = null, int commandTimeout = 30, CancellationToken token = default);
/// <summary>
/// Gets a <see cref="IAsyncEnumerable{T}"/> based on the <typeparamref name="T"/> sent into the function to create an object list based on the query passed into the routine
/// </summary>
/// <typeparam name="T">An instance of the type the caller wants to create from the query passed into procedure</typeparam>
/// <param name="commandTimeout">The wait time in seconds before terminating the attempt to execute a command and generating an error</param>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="queryCommandType">Represents how a command should be interpreted by the data provider</param>
/// <param name="parameters">The database parameters that are associated with a query</param>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <returns>Returns a <see cref="IAsyncEnumerable{T}"/> based on the results of the passed in <paramref name="query"/></returns>
IAsyncEnumerable<T> GetDataObjectsStreamAsync<T>(string query, CommandType queryCommandType, IEnumerable<DbParameter> parameters = null, int commandTimeout = 30, CancellationToken token = default) where T : class;
#endif
/// <summary>
/// Utility method for returning an <see cref="IEnumerable{T}"/> of scalar values from the database
/// </summary>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <param name="commandTimeout">The wait time in seconds before terminating the attempt to execute a command and generating an error</param>
/// <param name="parameters">The parameters associated with a database query</param>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="queryCommandType">Represents how a command should be interpreted by the data provider</param>
/// <typeparam name="T">The data type to return from data value returned from the query</typeparam>
/// <returns>Returns an <see cref="IEnumerable{T}"/> of the value of the first column in the result set as an instance of <typeparamref name="T"/></returns>
Task<IEnumerable<T>> GetScalarValuesAsync<T>(string query, CommandType queryCommandType, IEnumerable<DbParameter> parameters = null, int commandTimeout = 30, CancellationToken token = default);
/// <summary>
/// Gets a single instance of <typeparamref name="T"/> based on the <paramref name="query"/> passed into the routine
/// </summary>
/// <typeparam name="T">An instance of the type the caller wants create from the query passed into procedure</typeparam>
/// <param name="commandTimeout">The wait time in seconds before terminating the attempt to execute a command and generating an error</param>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="queryCommandType">Represents how a command should be interpreted by the data provider</param>
/// <param name="parameters">The database parameters associated with a query</param>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <returns>Gets an instance of <typeparamref name="T"/> based on the <paramref name="query"/> passed into the routine</returns>
Task<T> GetDataObjectAsync<T>(string query, CommandType queryCommandType, IEnumerable<DbParameter> parameters = null, int commandTimeout = 30, CancellationToken token = default) where T : class;
/// <summary>
/// Gets a <see cref="IEnumerable{T}"/> of the type parameter object that creates an object based on the query passed into the routine
/// </summary>
/// <typeparam name="T">An instance of the type caller wants create from the query passed into procedure</typeparam>
/// <param name="commandTimeout">The wait time in seconds before terminating the attempt to execute a command and generating an error</param>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="queryCommandType">Represents how a command should be interpreted by the data provider</param>
/// <param name="parameters">The database parameters that are associated with a query</param>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <returns>Returns a <see cref="IEnumerable{T}"/> based on the results of the passed in <paramref name="query"/></returns>
Task<IEnumerable<T>> GetDataObjectsAsync<T>(string query, CommandType queryCommandType, IEnumerable<DbParameter> parameters = null, int commandTimeout = 30, CancellationToken token = default) where T : class;
/// <summary>
/// Utility method for returning a <see cref="Task{DbDataReader}"/> object
/// </summary>
/// <param name="parameters">The database parameters that are associated with a query</param>
/// <param name="commandTimeout">The wait time in seconds before terminating the attempt to execute a command and generating an error</param>
/// <param name="behavior">Provides a description of the results of the query and its effect on the database. Defaults to <see cref="CommandBehavior.Default"/></param>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <param name="queryCommandType">Represents how a command should be interpreted by the data provider</param>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <returns>A DbDataReader object, the caller is responsible for handling closing the DataReader. Once the data reader is closed, the Database Connection will be closed as well</returns>
Task<DbDataReader> GetDbDataReaderAsync(string query, CommandType queryCommandType, IEnumerable<DbParameter> parameters = null, int commandTimeout = 30, CommandBehavior behavior = CommandBehavior.Default, CancellationToken token = default);
/// <summary>
/// Utility method for returning a <see cref="Task{Object}"/> from the database
/// </summary>
/// <param name="commandTimeout">The wait time in seconds before terminating the attempt to execute a command and generating an error</param>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <param name="parameters">The database parameters that are associated with a query</param>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="queryCommandType">Represents how a command should be interpreted by the data provider</param>
/// <typeparam name="T">The data type to return from data value returned from the query</typeparam>
/// <returns>Returns the value of the first column in the first row as an instance of <typeparamref name="T"/></returns>
Task<T> GetScalarValueAsync<T>(string query, CommandType queryCommandType, IEnumerable<DbParameter> parameters = null, int commandTimeout = 30, CancellationToken token = default);
/// <summary>
/// Utility method for returning an instance of <see cref="IMultiResultReader"/> asynchronously
/// </summary>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <param name="commandTimeout">The wait time in seconds before terminating the attempt to execute a command and generating an error</param>
/// <param name="parameters">The query database parameters that are associated with a query</param>
/// <param name="queryCommandType">Represents how a command should be interpreted by the data provider</param>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <returns>An instance of <see cref="IMultiResultReader"/> object</returns>
Task<IMultiResultReader> GetMultiResultReaderAsync(string query, CommandType queryCommandType, IEnumerable<DbParameter> parameters = null, int commandTimeout = 30, CancellationToken token = default);
#endregion
#region Data Modification
/// <summary>
/// Utility method for executing an Ad-Hoc query or stored procedure
/// </summary>
/// <param name="commandTimeout">The wait time in seconds before terminating the attempt to execute a command and generating an error</param>
/// <param name="parameters">The query database parameters that are associated with a query</param>
/// <param name="token">Propagates notification that operations should be canceled</param>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="queryCommandType">Represents how a command should be interpreted by the data provider</param>
/// <returns>Returns the number of rows affected by this query as a <see cref="Task"/></returns>
Task<int> ExecuteNonQueryAsync(string query, CommandType queryCommandType, IEnumerable<DbParameter> parameters = null, int commandTimeout = 30, CancellationToken token = default);
#endregion
}
}