using System.Data;
using System.Data.Common;
using Elsa.Sql.Models;
namespace Elsa.Sql.Client;
public abstract class BaseSqlClient : ISqlClient
{
///
/// The connection string used to connect with the database.
///
protected readonly string _connectionString;
///
/// The marker used when injecting parameters into a query.
/// Default: "@"
///
public virtual string ParameterMarker { get; set; } = "@";
///
/// The text following the ParameterMarker when injecting parameters into a query.
/// Default: "param"
///
public virtual string ParameterText { get; set; } = "p";
///
/// Set to true to add a counter to the end of the parameter string.
/// Default: true
///
public virtual bool IncrementParameter { get; set; } = true;
///
/// Create a connection using the client specific connection.
///
///
protected abstract DbConnection CreateConnection();
///
/// Create a command using the client specific connection.
///
///
///
///
protected abstract DbCommand CreateCommand(string query, DbConnection connection);
///
///
///
///
protected BaseSqlClient(string connectionString) => _connectionString = connectionString;
///
///
///
public async Task ExecuteCommandAsync(EvaluatedQuery evaluatedQuery)
{
using var connection = CreateConnection();
connection.Open();
var command = CreateCommand(evaluatedQuery.Query, connection);
AddCommandParameters(command, evaluatedQuery.Parameters);
var result = await command.ExecuteNonQueryAsync();
return result;
}
///
///
///
public async Task