-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make executing a query an extension method on IDbConnection. It could…
… make integration with e.g. Dapper easier
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Data; | ||
using System.Threading.Tasks; | ||
|
||
namespace WeelinkIT.FluentSQL.Extensions | ||
{ | ||
/// <summary> | ||
/// Extends <see cref="IDbConnection" /> for executing queries. | ||
/// </summary> | ||
public static class QueryExtensions | ||
{ | ||
/// <summary> | ||
/// Execute this query and return the result. | ||
/// </summary> | ||
/// <param name="connection">The <see cref="IDbConnection" />.</param> | ||
/// <param name="query">The query to execute.</param> | ||
/// <param name="parameterConfig">Configures the parameters.</param> | ||
/// <param name="transaction">The optional transaction.</param> | ||
/// <returns>The result of the query.</returns> | ||
public static Task<TQueryResult> ExecuteAsync<TParameters, TQueryResult>( | ||
this IDbConnection connection, | ||
Query<TParameters, TQueryResult> query, | ||
Action<TParameters> parameterConfig, | ||
IDbTransaction transaction = null) where TParameters : new() | ||
{ | ||
var parameters = new TParameters(); | ||
parameterConfig(parameters); | ||
|
||
return Task.FromResult(default(TQueryResult)); | ||
} | ||
|
||
/// <summary> | ||
/// Execute this query and return the result. | ||
/// </summary> | ||
/// <param name="connection">The <see cref="IDbConnection" />.</param> | ||
/// <param name="query">The query to execute.</param> | ||
/// <param name="transaction">The optional transaction.</param> | ||
/// <returns>The result of the query.</returns> | ||
public static Task<TQueryResult> ExecuteAsync<TQueryResult>( | ||
this IDbConnection connection, | ||
Query<TQueryResult> query, | ||
IDbTransaction transaction = null) | ||
{ | ||
return Task.FromResult(default(TQueryResult)); | ||
} | ||
} | ||
} |