Skip to content

Commit

Permalink
Dapper updates
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Jan 25, 2025
1 parent e173630 commit f6a62e6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/Shiny.Mediator.DapperRequests/Contracts.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace Shiny.Mediator;
using System.Data;

namespace Shiny.Mediator;


public record DapperRequest<TResult>(
FormattableString Sql,
int? CommandTimeout = null,
string? RequestKey = null
) : IRequest<TResult>, IRequestKey
{
Expand All @@ -19,29 +20,32 @@ public string GetKey()
public record DapperQuery<TResult>(
FormattableString Sql,
int? CommandTimeout = null,
IDbTransaction? Transaction = null,
CommandType? CommandType = null,
string? RequestKey = null
) : DapperRequest<IEnumerable<TResult>>(
Sql,
CommandTimeout,
RequestKey
);

public record DapperFirstQuery<TResult>(
FormattableString Sql,
int? CommandTimeout = null,
IDbTransaction? Transaction = null,
CommandType? CommandType = null,
string? RequestKey = null
) : DapperRequest<TResult>(
Sql,
CommandTimeout,
RequestKey
);

public record DapperScalar(
FormattableString Sql,
int? CommandTimeout = null,
IDbTransaction? Transaction = null,
CommandType? CommandType = null,
string? RequestKey = null
) : DapperRequest<object>(
Sql,
CommandTimeout,
RequestKey
);
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ CancellationToken cancellationToken
.Create(request)
.QueryBuilder(request.Sql)
.QueryFirstOrDefaultAsync<TResult>(
commandTimeout: request.CommandTimeout,
cancellationToken: cancellationToken
request.Transaction,
request.CommandTimeout,
request.CommandType,
cancellationToken
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ CancellationToken cancellationToken
.Create(request)
.QueryBuilder(request.Sql)
.QueryAsync<TResult>(
null,
request.Transaction,
request.CommandTimeout,
cancellationToken: cancellationToken
request.CommandType,
cancellationToken
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ public Task<object> Handle(DapperScalar request, RequestContext<DapperScalar> co
=> connectionProvider
.Create(request)
.QueryBuilder(request.Sql)
.ExecuteScalarAsync(null, request.CommandTimeout, cancellationToken: cancellationToken);
.ExecuteScalarAsync(
request.Transaction,
request.CommandTimeout,
request.CommandType,
cancellationToken
);
}

0 comments on commit f6a62e6

Please sign in to comment.