Skip to content

SQL Builder - statement builder#1191

Open
michalkrzyz wants to merge 8 commits into
mainfrom
mikrzyz/issue-1062.4
Open

SQL Builder - statement builder#1191
michalkrzyz wants to merge 8 commits into
mainfrom
mikrzyz/issue-1062.4

Conversation

@michalkrzyz
Copy link
Copy Markdown
Collaborator

@michalkrzyz michalkrzyz commented May 8, 2026

Description

  • Add Order struct
  • Add common statement

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

  • Related Issue # (issue)
  • Closes # (issue)
  • Fixes # (issue)

Remove if not applicable

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help
  • Separate ticket for tests # (issue/pr)

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Added to documentation?

  • 📜 README.md
  • 🤝 Documentation pages updated
  • 🙅 no documentation needed
  • (if applicable) generated OpenAPI docs for CRD changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copilot AI review requested due to automatic review settings May 8, 2026 16:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors MariaDB query construction by introducing a shared statement builder and a new Order helper type, then migrates multiple query builders to use these abstractions for consistent join/filter/cursor handling.

Changes:

  • Added generic BuildStatement(...) + Statement configuration to centralize SQL assembly (joins, WHERE/HAVING cursor clauses, ORDER BY, parameters).
  • Replaced []entity.Order string-building helpers with a dedicated Order type (String(), By*() helpers) and updated join-condition signatures accordingly.
  • Removed per-entity ensure*Filter(...) helpers in favor of a generic EnsureFilter(...).

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/database/mariadb/user.go Migrates user statement construction to Statement/BuildStatement and EnsureFilter.
internal/database/mariadb/support_group.go Migrates support group statement construction to Statement/BuildStatement and EnsureFilter.
internal/database/mariadb/service.go Migrates service statement construction to Statement/BuildStatement, introduces Order usage in aggregation queries.
internal/database/mariadb/service_issue_variant.go Migrates statement construction to Statement/BuildStatement; adjusts base query placeholders.
internal/database/mariadb/scanner_run.go Replaces local filter initialization with EnsureFilter.
internal/database/mariadb/remediation.go Migrates remediation statement construction to Statement/BuildStatement; adjusts base query placeholders and EnsureFilter.
internal/database/mariadb/patch.go Migrates patch statement construction to Statement/BuildStatement; adjusts base query placeholders and EnsureFilter.
internal/database/mariadb/order.go Introduces Order type (string formatting + helper predicates like ByCount).
internal/database/mariadb/mv_vulnerabilities.go Replaces issue filter initialization with EnsureFilter.
internal/database/mariadb/issue.go Refactors issue statement building into Statement/BuildStatement; updates join conditions to use *Order.
internal/database/mariadb/issue_variant.go Migrates issue-variant statement construction to Statement/BuildStatement and EnsureFilter.
internal/database/mariadb/issue_repository.go Migrates issue-repository statement construction to Statement/BuildStatement and EnsureFilter.
internal/database/mariadb/issue_match.go Migrates issue-match statement construction to Statement/BuildStatement; updates column handling and base query formatting.
internal/database/mariadb/db_object.go Adds shared statement builder, EnsureFilter, IsNil, and updates join planning/cursor query helpers to use *Order.
internal/database/mariadb/db_object_test.go Updates join condition tests to the new *Order signature.
internal/database/mariadb/component.go Migrates component statement construction to Statement/BuildStatement; updates join conditions/order predicates.
internal/database/mariadb/component_version.go Migrates component-version statement construction to Statement/BuildStatement; updates join conditions/order predicates.
internal/database/mariadb/component_instance.go Migrates component-instance statement construction to Statement/BuildStatement; updates join conditions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +184 to +191
} else {
if filter != nil {
if do.GetFilterQuery(filter) != "" && withCursor && cursorQuery != "" {
cursorQuery = fmt.Sprintf(" AND (%s)", cursorQuery)
}
} else {
panic("hasFilter for not aggregated query has to be passed (has to be not nil).")
}
Comment on lines +217 to +228
func BuildStatement[
T any,
PT interface {
*T
entity.HasPagination
},
](s Statement, filter PT) (Stmt, []any, error) {
filter = EnsureFilter(filter)
s.L.WithFields(logrus.Fields{"filter": filter})

joins := s.Obj.GetJoins(filter, s.Order)
whereClause := s.Obj.GetFilterWhereClause(filter, s.CheckCursorInWhere && s.WithCursor)
Comment thread internal/database/mariadb/user.go
- add Order in db layer
- change some parameters from []entity.Order to *Order
- move Order functions to new type

On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
f
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
@michalkrzyz michalkrzyz force-pushed the mikrzyz/issue-1062.4 branch from 2428c9d to 44bb26c Compare May 11, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants