Added & using prepared statements for stores

This commit is contained in:
Tom
2024-10-29 12:13:38 +00:00
parent 94e0d54c31
commit e7b06f1634
9 changed files with 232 additions and 65 deletions

View File

@@ -69,6 +69,18 @@ namespace HermesSocketLibrary.db
return await command.ExecuteNonQueryAsync();
}
public async Task<int> ExecuteTransaction(string sql, Action<NpgsqlCommand> prepare)
{
await using var connection = await _source.OpenConnectionAsync();
await using var transaction = await connection.BeginTransactionAsync();
await using var command = new NpgsqlCommand(sql, connection, transaction);
prepare(command);
await command.PrepareAsync();
var results = await command.ExecuteNonQueryAsync();
await transaction.CommitAsync();
return results;
}
public async Task<object?> ExecuteScalar(string sql, IDictionary<string, object>? values = null)
{
await using var connection = await _source.OpenConnectionAsync();