diff --git a/README.md b/README.md
index 5d40e52..f9aebb5 100644
--- a/README.md
+++ b/README.md
@@ -7,17 +7,17 @@ This package is a simple, easy and fluent way to execute SQL on database connect
You can install the package using one of the options bellow:
- Package Manager
```
-PM> NuGet\Install-Package Dapper.FluentExecution -Version 0.1.1
+PM> NuGet\Install-Package Dapper.FluentExecution -Version 0.2.0
```
- .NET CLI
```
-dotnet add package Dapper.FluentExecution --version 0.1.1
+dotnet add package Dapper.FluentExecution --version 0.2.0
```
- PackageReference
```
-
+
```
## Usage
@@ -49,14 +49,13 @@ public async Task GetByIdAsync(int id, int? specificAddressId, Cancella
.WithParameter("@Id", id)
.QuerySingleOrDefaultAsync(cancellation);
```
-## TODO - v0.2.0
-- [ ] Add unit tests for `IExecutionBuilder` methods
-- [ ] Add summary doc on all .cs files
-- [ ] Add suport to `Execution` methods on `IExecutionBuilder`. E.g.: `Execute, ExecuteAsync, ExecuteScalar, ExecuteScalarAsync...`.
-- [ ] Add support to dynamic parameter by dynamic object. E.g.: `new { Param1 = "1", Param2 = 2 }`
-- [ ] Add support to set command timeout
-- [ ] Add support to set query as an execution of stored procedure
-- [ ] Add `QueryAsync, Query,...` an `IEnumerable` result
+## Release - v0.2.0
+- Add summary doc on all .cs files
+- Add suport to `Execution` methods on `IExecutionBuilder`. E.g.: `Execute, ExecuteAsync, ExecuteScalar, ExecuteScalarAsync...`.
+- Add support to dynamic parameter by dynamic object. E.g.: `new { Param1 = "1", Param2 = 2 }`
+- Add support to set command timeout
+- Add support to set query as an execution of stored procedure
+- Add `QueryAsync, Query,...` an `IEnumerable` result
## Release - v0.1.1
- Fixing `csproj` documentation to Nuget.org
diff --git a/src/fluent-execution/AsyncResult.cs b/src/fluent-execution/AsyncResult.cs
index 7995684..bc766d5 100644
--- a/src/fluent-execution/AsyncResult.cs
+++ b/src/fluent-execution/AsyncResult.cs
@@ -1,5 +1,8 @@
namespace Dapper.FluentExecution;
+///
+///It's helper struct to allows returns a async result at fluent way
+///
public struct AsyncResult
{
private readonly Task> taskResult;
@@ -9,6 +12,16 @@ internal AsyncResult(Task> result)
this.taskResult = result;
}
+ ///
+ ///Performs an awaitable result as of
+ ///
+ ///An IEnumerable of
+ public async Task> GetResultAsync() => await taskResult;
+
+ ///
+ ///Performs awaitable result as a of
+ ///
+ ///A list of
public async Task> ToListAsync()
{
var newResult = await taskResult;
@@ -16,6 +29,10 @@ public async Task> ToListAsync()
return newResult.ToList();
}
+ ///
+ ///Performs an awaitable result as an of
+ ///
+ ///An array of
public async Task ToArrayAsync()
{
var newResult = await taskResult;
diff --git a/src/fluent-execution/Dapper.FluentExecution.csproj b/src/fluent-execution/Dapper.FluentExecution.csproj
index f6b0285..71f050b 100644
--- a/src/fluent-execution/Dapper.FluentExecution.csproj
+++ b/src/fluent-execution/Dapper.FluentExecution.csproj
@@ -14,7 +14,7 @@
Augusto Mesquita
Aucamana
augustodeveloper
- 0.1.1
+ 0.2.0
Dapper.FluentExecution
Dapper;Dapper.Fluent;Dapper.Query;Execution;Dapper.Execution
MIT
diff --git a/src/fluent-execution/ExecutionSqlBuilder.cs b/src/fluent-execution/ExecutionSqlBuilder.cs
index 447dccb..6641df0 100644
--- a/src/fluent-execution/ExecutionSqlBuilder.cs
+++ b/src/fluent-execution/ExecutionSqlBuilder.cs
@@ -10,6 +10,8 @@ internal class ExecutionSqlBuilder : IExecutionBuilder
private readonly StringBuilder sqlBuilder;
private DynamicParameters? parameters;
private IDbTransaction? transaction;
+ private CommandType commandType;
+ private TimeSpan? commandTimeout;
private DynamicParameters Parameters => GetParameters();
@@ -17,6 +19,7 @@ protected ExecutionSqlBuilder(string rootSql, IDbConnection connection)
{
this.connection = connection;
this.sqlBuilder = new(rootSql);
+ this.commandType = CommandType.Text;
}
internal static IExecutionBuilder New(string? sql, IDbConnection? connection)
@@ -33,7 +36,6 @@ internal static IExecutionBuilder New(string? sql, IDbConnection? connection)
#else
ArgumentNullException.ThrowIfNull(connection);
#endif
-
return new ExecutionSqlBuilder(sql!, connection!);
}
@@ -47,8 +49,23 @@ private DynamicParameters GetParameters()
return parameters;
}
+ private int? GetCommandTimeout()
+ {
+ if (!commandTimeout.HasValue)
+ {
+ return null;
+ }
+
+ if (commandTimeout.Value.Seconds < 1)
+ {
+ return null;
+ }
+
+ return commandTimeout.Value.Seconds;
+ }
+
private CommandDefinition BuildCommandDefinition(CancellationToken cancellation = default)
- => new CommandDefinition(sqlBuilder.ToString(), parameters, transaction: transaction, cancellationToken: cancellation);
+ => new CommandDefinition(sqlBuilder.ToString(), parameters, transaction, GetCommandTimeout(), commandType, cancellationToken: cancellation);
IExecutionBuilder IExecutionBuilder.WithTransaction(IDbTransaction transaction)
{
@@ -57,6 +74,16 @@ IExecutionBuilder IExecutionBuilder.WithTransaction(IDbTransaction transaction)
return this;
}
+ IExecutionBuilder IExecutionBuilder.AsStoredProcedure()
+ {
+ if (commandType != CommandType.StoredProcedure)
+ {
+ commandType = CommandType.StoredProcedure;
+ }
+
+ return this;
+ }
+
IExecutionBuilder IExecutionBuilder.AppendSql(bool condition, string sql)
{
if (condition)
@@ -118,6 +145,29 @@ IExecutionBuilder IExecutionBuilder.WithParameter(string parameterName, object v
return this;
}
+ IExecutionBuilder IExecutionBuilder.WithParameter(bool condition, object values)
+ {
+ if (condition)
+ {
+ Parameters.AddDynamicParams(values);
+ }
+
+ return this;
+ }
+
+ IExecutionBuilder IExecutionBuilder.WithParameter(object values)
+ {
+ Parameters.AddDynamicParams(values);
+
+ return this;
+ }
+
+ IExecutionBuilder IExecutionBuilder.WithCommandTimeout(TimeSpan timeout)
+ {
+ this.commandTimeout = timeout;
+ return this;
+ }
+
IEnumerable IExecutionBuilder.Query() => this.connection.Query(BuildCommandDefinition());
IEnumerable IExecutionBuilder.Query() => this.connection.Query(BuildCommandDefinition());
@@ -158,15 +208,9 @@ AsyncResult IExecutionBuilder.QueryAsync(CancellationToken cancellation
return new(result);
}
- async Task IExecutionBuilder.QuerySingleAsync(CancellationToken cancellation)
- {
- return await this.connection.QuerySingleAsync(BuildCommandDefinition(cancellation));
- }
+ async Task IExecutionBuilder.QuerySingleAsync(CancellationToken cancellation) => await this.connection.QuerySingleAsync(BuildCommandDefinition(cancellation));
- async Task IExecutionBuilder.QuerySingleAsync(CancellationToken cancellation)
- {
- return await this.connection.QuerySingleAsync(BuildCommandDefinition(cancellation));
- }
+ async Task IExecutionBuilder.QuerySingleAsync(CancellationToken cancellation) => await this.connection.QuerySingleAsync(BuildCommandDefinition(cancellation));
async Task IExecutionBuilder.QuerySingleOrDefaultAsync(CancellationToken cancellation)
{
@@ -193,15 +237,9 @@ async Task IExecutionBuilder.QuerySingleAsync(CancellationToken cancellati
}
- async Task IExecutionBuilder.QueryFirstAsync(CancellationToken cancellation)
- {
- return await this.connection.QueryFirstAsync(BuildCommandDefinition(cancellation));
- }
+ async Task IExecutionBuilder.QueryFirstAsync(CancellationToken cancellation) => await this.connection.QueryFirstAsync(BuildCommandDefinition(cancellation));
- async Task IExecutionBuilder.QueryFirstAsync(CancellationToken cancellation)
- {
- return await this.connection.QueryFirstAsync(BuildCommandDefinition(cancellation));
- }
+ async Task IExecutionBuilder.QueryFirstAsync(CancellationToken cancellation) => await this.connection.QueryFirstAsync(BuildCommandDefinition(cancellation));
async Task IExecutionBuilder.QueryFirstOrDefaultAsync(CancellationToken cancellation)
{
@@ -232,4 +270,20 @@ async Task IExecutionBuilder.QueryMultipleAsync(Func this.connection.Execute(BuildCommandDefinition());
+
+ async Task IExecutionBuilder.ExecuteAsync(CancellationToken cancellation) => await this.connection.ExecuteAsync(BuildCommandDefinition(cancellation));
+
+ object IExecutionBuilder.ExecuteScalar() => this.connection.ExecuteScalar(BuildCommandDefinition());
+
+ T IExecutionBuilder.ExecuteScalar() => this.connection.ExecuteScalar(BuildCommandDefinition());
+
+ async Task