Skip to content

Commit

Permalink
Add HavingAnd and HavingOr to the ISqlBuilder (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Jul 23, 2024
1 parent 85bbc03 commit d21bc4a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/YesSql.Abstractions/ISqlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ public interface ISqlBuilder
IEnumerable<string> GetSelectors();
IEnumerable<string> GetOrders();
void Join(JoinType type, string table, string onTable, string onColumn, string toTable, string toColumn, string schema, string alias = null, string toAlias = null);
void HavingAnd(string having);
void HavingOr(string having);
}
}
38 changes: 34 additions & 4 deletions src/YesSql.Core/Sql/SqlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,36 @@ public virtual void WhereAnd(string where)
WhereSegments.Add(where);
}

public virtual void HavingAnd(string having)
{
if (string.IsNullOrWhiteSpace(having))
{
return;
}

if (HavingSegments.Count > 0)
{
HavingSegments.Add(" AND ");
}

HavingSegments.Add(having);
}

public virtual void HavingOr(string having)
{
if (string.IsNullOrWhiteSpace(having))
{
return;
}

if (HavingSegments.Count > 0)
{
HavingSegments.Add(" OR ");
}

HavingSegments.Add(having);
}

public bool HasJoin
=> _join?.Count > 0;

Expand Down Expand Up @@ -297,14 +327,14 @@ public virtual void ThenOrderByRandom()
OrderSegments.Add(_dialect.RandomOrderByClause);
}

public virtual void GroupBy(string orderBy)
public virtual void GroupBy(string groupBy)
{
GroupSegments.Add(orderBy);
GroupSegments.Add(groupBy);
}

public virtual void Having(string orderBy)
public virtual void Having(string having)
{
HavingSegments.Add(orderBy);
HavingSegments.Add(having);
}

public virtual void Trail(string segment)
Expand Down

0 comments on commit d21bc4a

Please sign in to comment.