feat(etl): add parameters support to SqlScriptRunner
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Dapper;
|
||||
using JdeScoping.DataAccess.Interfaces;
|
||||
using JdeScoping.DataSync.Etl.Contracts;
|
||||
|
||||
@@ -7,6 +8,7 @@ public class SqlScriptRunner : IScriptRunner
|
||||
{
|
||||
private readonly IDbConnectionFactory _connectionFactory;
|
||||
private readonly string _sql;
|
||||
private readonly object? _parameters;
|
||||
private readonly int _timeoutSeconds;
|
||||
|
||||
public string ScriptName { get; }
|
||||
@@ -15,6 +17,7 @@ public class SqlScriptRunner : IScriptRunner
|
||||
IDbConnectionFactory connectionFactory,
|
||||
string sql,
|
||||
string? name = null,
|
||||
object? parameters = null,
|
||||
int timeoutSeconds = 3600)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(connectionFactory);
|
||||
@@ -22,6 +25,7 @@ public class SqlScriptRunner : IScriptRunner
|
||||
|
||||
_connectionFactory = connectionFactory;
|
||||
_sql = sql;
|
||||
_parameters = parameters;
|
||||
_timeoutSeconds = timeoutSeconds;
|
||||
ScriptName = name ?? "SqlScript";
|
||||
}
|
||||
@@ -29,9 +33,11 @@ public class SqlScriptRunner : IScriptRunner
|
||||
public async Task ExecuteAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
await using var connection = await _connectionFactory.CreateLotFinderConnectionAsync(cancellationToken);
|
||||
await using var command = connection.CreateCommand();
|
||||
command.CommandText = _sql;
|
||||
command.CommandTimeout = _timeoutSeconds;
|
||||
await command.ExecuteNonQueryAsync(cancellationToken);
|
||||
await connection.ExecuteAsync(
|
||||
new CommandDefinition(
|
||||
_sql,
|
||||
_parameters,
|
||||
commandTimeout: _timeoutSeconds,
|
||||
cancellationToken: cancellationToken));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user