From d21bc4a192846f8a8f450a58f1cdc044343d999f Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Tue, 23 Jul 2024 09:34:02 -0700 Subject: [PATCH] Add HavingAnd and HavingOr to the ISqlBuilder (#566) --- src/YesSql.Abstractions/ISqlBuilder.cs | 2 ++ src/YesSql.Core/Sql/SqlBuilder.cs | 38 +++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/YesSql.Abstractions/ISqlBuilder.cs b/src/YesSql.Abstractions/ISqlBuilder.cs index 8fde28ed..abad9a0c 100644 --- a/src/YesSql.Abstractions/ISqlBuilder.cs +++ b/src/YesSql.Abstractions/ISqlBuilder.cs @@ -44,5 +44,7 @@ public interface ISqlBuilder IEnumerable GetSelectors(); IEnumerable 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); } } diff --git a/src/YesSql.Core/Sql/SqlBuilder.cs b/src/YesSql.Core/Sql/SqlBuilder.cs index b1608f2f..321670f6 100644 --- a/src/YesSql.Core/Sql/SqlBuilder.cs +++ b/src/YesSql.Core/Sql/SqlBuilder.cs @@ -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; @@ -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)