Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/458 #459

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Lanceur.Infra.SQLite/DbActions/AliasDbAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,25 @@ public AliasDbAction(IDbConnectionManager db, ILoggerFactory logFactory)

#region Methods

private static void CreateAdditionalParameters(long idAlias, IEnumerable<QueryResultAdditionalParameters> parameters, IDbTransaction tx)
private void CreateAdditionalParameters(long idAlias, IEnumerable<QueryResultAdditionalParameters> parameters, IDbTransaction tx)
{
using var _ = _logger.BeginSingleScope("Parameters", parameters);
const string sql1 = "delete from alias_argument where id_alias = @idAlias";
const string sql2 = "insert into alias_argument (id_alias, argument, name) values(@idAlias, @parameter, @name);";

// Remove existing additional alias parameters
tx.Connection.Execute(sql1, new { idAlias });
var deletedRowsCount = tx.Connection.Execute(sql1, new { idAlias });

// Create alias additional parameters
tx.Connection.Execute(sql2, parameters.ToEntity(idAlias));
var addedRowsCount = tx.Connection.Execute(sql2, parameters.ToEntity(idAlias));

if (deletedRowsCount > 0 && addedRowsCount == 0)
{
_logger.LogWarning("Deleting {DeletedRowsCount} parameters while adding no new parameters", deletedRowsCount);
}
}

private static void CreateAdditionalParameters(AliasQueryResult alias, IDbTransaction tx)
private void CreateAdditionalParameters(AliasQueryResult alias, IDbTransaction tx)
=> CreateAdditionalParameters(alias.Id, alias.AdditionalParameters, tx);

private static void UpdateName(AliasQueryResult alias, IDbTransaction tx)
Expand Down
11 changes: 8 additions & 3 deletions src/Lanceur.Infra.SQLite/Entities/AdditionalParameterMixin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ public static class AdditionalParameterMixin
#region Methods

public static IEnumerable<AdditionalParameter>
ToEntity(this IEnumerable<QueryResultAdditionalParameters> collection, long idAlias) => collection
.Select(item => new AdditionalParameter { Id = item.Id, IdAlias = idAlias, Name = item.Name, Parameter = item.Parameter })
.ToList();
ToEntity(this IEnumerable<QueryResultAdditionalParameters> collection, long idAlias) => collection.Select(
item => new AdditionalParameter
{
Id = item.Id,
IdAlias = idAlias,
Name = item.Name,
Parameter = item.Parameter
}).ToList();

#endregion Methods
}
2 changes: 1 addition & 1 deletion src/Lanceur.Infra.SQLite/SqliteRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public void SetUsage(QueryResult alias)
_setUsageDbAction.SetUsage(ref alias, idSession);

if (alias is AliasQueryResult aqr) { _aliasDbAction.Update(aqr); }
else _logger.LogWarning("Alias {AliasName} is not an AliasQueryResult", alias.Name);
else _logger.LogInformation("Alias {AliasName} is not an AliasQueryResult", alias.Name);
}

public void SetUsage(string aliasName) => SetUsage(new AliasQueryResult() { Name = aliasName });
Expand Down
Loading