Skip to content

Commit

Permalink
Make executing a query an extension method on IDbConnection. It could…
Browse files Browse the repository at this point in the history
… make integration with e.g. Dapper easier
  • Loading branch information
weelink committed Jun 20, 2019
1 parent cf825e0 commit fea4847
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Weelink-IT.FluentSQL/Extensions/QueryExtensions.cs
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));
}
}
}

0 comments on commit fea4847

Please sign in to comment.