Skip to content

Commit

Permalink
Fix: Adjusted column alias handling in Select method to avoid empty a…
Browse files Browse the repository at this point in the history
…lias.
  • Loading branch information
mk3008 committed Oct 14, 2024
1 parent 79a283e commit a70edab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Carbunql/Fluent/SelectQuerySelectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ public static SelectQuery SelectOnlyByNames(this SelectQuery query, IEnumerable<
return query;
}

/// <summary>
/// Adds a column selection to the query with an optional alias.
/// If the provided alias is null or empty, the column name will be used as the alias.
/// </summary>
/// <param name="query">The current SelectQuery object.</param>
/// <param name="tableAlias">The alias of the table that contains the column.</param>
/// <param name="column">The name of the column to select.</param>
/// <param name="columnAlias">Optional alias for the column. If not provided or empty, the column name will be used.</param>
/// <returns>The updated SelectQuery object.</returns>
public static SelectQuery Select(this SelectQuery query, string tableAlias, string column, string columnAlias = "")
{
query.AddSelect($"{tableAlias}.{column}", columnAlias);
query.AddSelect($"{tableAlias}.{column}", string.IsNullOrEmpty(columnAlias) ? column : columnAlias);
return query;
}

Expand Down
1 change: 1 addition & 0 deletions src/Carbunql/IQuerySource.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Carbunql.Building;
using Carbunql.Clauses;
using Carbunql.Extensions;
using Carbunql.Tables;

namespace Carbunql;
Expand Down

0 comments on commit a70edab

Please sign in to comment.