feat(etl): implement SqlScriptRunner
Add SqlScriptRunner class that implements IScriptRunner for executing SQL scripts against the LotFinderDB cache database. Includes constructor validation and configurable timeout support (default 1 hour).
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using JdeScoping.DataAccess.Interfaces;
|
||||
using JdeScoping.DataSync.Etl.Contracts;
|
||||
|
||||
namespace JdeScoping.DataSync.Etl.Scripts;
|
||||
|
||||
public class SqlScriptRunner : IScriptRunner
|
||||
{
|
||||
private readonly IDbConnectionFactory _connectionFactory;
|
||||
private readonly string _sql;
|
||||
private readonly int _timeoutSeconds;
|
||||
|
||||
public string ScriptName { get; }
|
||||
|
||||
public SqlScriptRunner(
|
||||
IDbConnectionFactory connectionFactory,
|
||||
string sql,
|
||||
string? name = null,
|
||||
int timeoutSeconds = 3600)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(connectionFactory);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(sql);
|
||||
|
||||
_connectionFactory = connectionFactory;
|
||||
_sql = sql;
|
||||
_timeoutSeconds = timeoutSeconds;
|
||||
ScriptName = name ?? "SqlScript";
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user