/
DbProvider.cs
177 lines (175 loc) · 14.2 KB
/
DbProvider.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
namespace ADO.Net.Client.Core
{
/// <summary>
/// Base class for all classes that query a database
/// </summary>
/// <seealso cref="IDbProvider" />
public abstract class DbProvider : IDbProvider
{
/// <summary>
/// An instance of <see cref="IConnectionManager"/>
/// </summary>
public abstract IConnectionManager ConnectionManager { get; }
/// <summary>
/// Utility method for returning a <see cref="Task{T}"/> value from the database
/// </summary>
/// <typeparam name="T">An instance of the type caller wants create from the query passed into procedure</typeparam>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <returns>Returns the value of the first column as <see cref="Task{T}"/></returns>
public abstract Task<T> GetScalarValueAsync<T>(ISqlQuery query, CancellationToken token = default);
/// <summary>
/// Utility method for returning a <see cref="Task{T}"/> value from the database
/// </summary>
/// <typeparam name="T">An instance of the type caller wants create from the query passed into procedure</typeparam>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <returns>Returns the value of the first column in the first row as <see cref="Task{T}"/></returns>
public abstract Task<IEnumerable<T>> GetScalarValuesAsync<T>(ISqlQuery query, CancellationToken token = default);
/// <summary>
/// Gets an instance of <see cref="IMultiResultReader"/> asynchronously
/// </summary>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <returns>Returns an instance of <see cref="IMultiResultReader"/></returns>
public abstract Task<IMultiResultReader> GetMultiResultReaderAsync(ISqlQuery query, CancellationToken token = default);
/// <summary>
/// Utility method for returning a <see cref="Task{DbDataReader}"/> object created from the passed in query
/// </summary>
/// <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="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <returns>A <see cref="Task{DbDataReader}"/> object, the caller is responsible for handling closing the <see cref="DbDataReader"/>. Once the data reader is closed, the database connection will be closed as well</returns>
public abstract Task<DbDataReader> GetDbDataReaderAsync(ISqlQuery query, CommandBehavior behavior = CommandBehavior.Default, CancellationToken token = default);
/// <summary>
/// Gets an instance of <see cref="DataTable"/> asynchronously
/// </summary>
/// <param name="query">SQL query to use to build a <see cref="DataTable"/></param>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <returns>Returns a <see cref="Task{TResult}"/> of datatable</returns>
public abstract Task<DataTable> GetDataTableAsync(ISqlQuery query, CancellationToken token = default);
/// <summary>
/// Gets an <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="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <returns>Returns a <see cref="IEnumerable{T}"/> of type parameter object based on the fields in the passed in query</returns>
public abstract Task<IEnumerable<T>> GetDataObjectsAsync<T>(ISqlQuery query, CancellationToken token = default) where T : class;
/// <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 caller wants create from the query passed into procedure</typeparam>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</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.
/// Or the default value of <typeparamref name="T"/> if there are no search results
/// </returns>
public abstract Task<T> GetDataObjectAsync<T>(ISqlQuery query, CancellationToken token = default) where T : class;
/// <summary>
/// Gets an <see cref="IEnumerable{T}"/> of the type parameter object that creates an object based on the query passed into the routine streame from the server
/// </summary>
/// <typeparam name="T">An instance of the type caller wants create from the query passed into procedure</typeparam>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <returns>Returns an <see cref="IEnumerable{T}"/> of type parameter object based on the fields in the passed in query</returns>
public abstract IAsyncEnumerable<T> GetDataObjectsStreamAsync<T>(ISqlQuery query, CancellationToken token = default) where T : class;
/// <summary>
/// Gets an instance of <see cref="IAsyncEnumerable{T}"/> of the type parameter object that creates an object based on the query passed into the routine streamed from the server
/// </summary>
/// <typeparam name="T">An instance of the type caller wants create from the query passed into procedure</typeparam>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</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>
public abstract IAsyncEnumerable<T> GetScalarValuesStreamAsync<T>(ISqlQuery query, 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 caller wants create from query passed into procedure</typeparam>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <returns>Gets an instance of <typeparamref name="T"/> based on the <paramref name="query"/> passed into the routine.
/// Or the default value of <typeparamref name="T"/> if there are no search results
/// </returns>
public abstract T GetDataObject<T>(ISqlQuery query) where T : class;
/// <summary>
/// Gets a list of the type parameter object that creates an object based on the query passed into the routine, streamed from the server
/// </summary>
/// <typeparam name="T">An instance of the type caller wants create from query passed into procedure</typeparam>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <returns>Returns a <see cref="IEnumerable{T}"/> based on the results of the passed in <paramref name="query"/></returns>
public abstract IEnumerable<T> GetDataObjectsStream<T>(ISqlQuery query) where T : class;
/// <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 caller wants create from the query passed into procedure</typeparam>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <returns>Gets an instance of <typeparamref name="T"/> based on the <paramref name="query"/> passed into the routine.
/// Or the default value of <typeparamref name="T"/> if there are no search results
/// </returns>
public abstract IEnumerable<T> GetDataObjects<T>(ISqlQuery query) where T : class;
/// <summary>
/// Gets an instance of <see cref="DataSet"/>
/// </summary>
/// <param name="query">SQL query to use to build a <see cref="DataSet"/></param>
/// <returns>Returns an instance of <see cref="DataSet"/> based on the <paramref name="query"/> passed into the routine</returns>
public abstract DataSet GetDataSet(ISqlQuery query);
/// <summary>
/// Utility method for returning a <see cref="DataTable"/> object created from the passed in query
/// </summary>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <returns>Returns a <see cref="DataTable"/> object</returns>
public abstract DataTable GetDataTable(ISqlQuery query);
/// <summary>
/// Utility method for returning a <see cref="DbDataReader"/> object created from the passed in query
/// </summary>
/// <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="query">The query command text or name of stored procedure to execute against the data store</param>
/// <returns>An instance of <see cref="DbDataReader"/> object, the caller is responsible for handling closing the <see cref="DbDataReader"/>. Once the data reader is closed, the database connection will be closed as well</returns>
public abstract DbDataReader GetDbDataReader(ISqlQuery query, CommandBehavior behavior = CommandBehavior.Default);
/// <summary>
/// Utility method for returning a scalar value from the database
/// </summary>
/// <typeparam name="T">An instance of the type caller wants create from the query passed into procedure</typeparam>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <returns>Returns the value of the first column in the first row as an instance of <typeparamref name="T"/></returns>
public abstract T GetScalarValue<T>(ISqlQuery query);
/// <summary>
/// Gets an instance of <see cref="IEnumerable{T}"/> of the type parameter object that creates an object based on the query passed into the routine streamed from the server
/// </summary>
/// <typeparam name="T">An instance of the type caller wants create from the query passed into procedure</typeparam>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <returns>Returns a <see cref="IEnumerable{T}"/> based on the results of the passed in <paramref name="query"/></returns>
public abstract IEnumerable<T> GetScalarValuesStream<T>(ISqlQuery query);
/// <summary>
/// Gets an instance of <see cref="IEnumerable{T}"/> of scalar values
/// </summary>
/// <typeparam name="T">An instance of the type caller wants create from the query passed into procedure</typeparam>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <returns>Returns a <see cref="IEnumerable{T}"/> based on the results of the passed in <paramref name="query"/></returns>
public abstract IEnumerable<T> GetScalarValues<T>(ISqlQuery query);
/// <summary>
/// Gets an instance of <see cref="IMultiResultReader"/>
/// </summary>
/// <param name="query">The query command text or name of stored procedure to execute against the data store</param>
/// <returns>Returns an instance of <see cref="IMultiResultReader"/></returns>
public abstract IMultiResultReader GetMultiResultReader(ISqlQuery query);
/// <summary>
/// Utility method for executing an Ad-Hoc query or stored procedure
/// </summary>
/// <param name="query">An instance of <see cref="ISqlQuery"/> used to query a data store</param>
/// <returns>Returns the amount of records affected by the passed in <paramref name="query"/></returns>
public abstract int ExecuteNonQuery(ISqlQuery query);
/// <summary>
/// Utility method for executing an Ad-Hoc query or stored procedure
/// </summary>
/// <param name="token">Structure that propogates a notification that an operation should be cancelled</param>
/// <param name="query">An instance of <see cref="ISqlQuery"/> used to query a data store</param>
/// <returns>Returns the number of rows affected by the passed in <paramref name="query"/></returns>
public abstract Task<int> ExecuteNonQueryAsync(ISqlQuery query, CancellationToken token = default);
}
}