Repository navigation
Refactor compiler to use the Visitor patterns - #787
Open
ahmad-moussawi wants to merge 2 commits into
Open
ahmad-moussawi wants to merge 2 commits into
ahmad-moussawi wants to merge 2 commits into
Conversation
added 2 commits
October 14, 2026 12:23
…er binding order with pagination modifiers
There was a problem hiding this comment.
🟡 Changes recommended
The visitor implementation has SQL-generation regressions for empty conditions, random ordering, and outer-variable resolution.
4 open findings
What changed in this PR
Refactors SQL compilation around a dedicated visitor-based CompileContext, leaving SqlResult as the final execution result.
Changes:
- Replaces string-returning compiler methods with visitor methods.
- Migrates dialect-specific pagination and condition compilation.
- Updates limit tests and adds binding-order coverage.
| File | Description |
|---|---|
QueryBuilder/SqlResult.cs |
Simplifies result construction defaults. |
QueryBuilder/Compilers/CompileContext.cs |
Adds compilation state and query-stack handling. |
QueryBuilder/Compilers/Compiler.cs |
Implements core visitor-based compilation. |
QueryBuilder/Compilers/Compiler.Conditions.cs |
Implements condition visitors. |
QueryBuilder/Compilers/SqlServerCompiler.cs |
Migrates SQL Server compilation. |
QueryBuilder/Compilers/SqliteCompiler.cs |
Migrates SQLite compilation. |
QueryBuilder/Compilers/PostgresCompiler.cs |
Migrates PostgreSQL compilation. |
QueryBuilder/Compilers/OracleCompiler.cs |
Migrates Oracle compilation. |
QueryBuilder/Compilers/MySqlCompiler.cs |
Migrates MySQL pagination. |
QueryBuilder/Compilers/FirebirdCompiler.cs |
Migrates Firebird compilation. |
QueryBuilder.Tests/SqlServer/SqlServerLimitTests.cs |
Uses CompileContext. |
QueryBuilder.Tests/SqlServer/SqlServerLegacyLimitTests.cs |
Uses CompileContext. |
QueryBuilder.Tests/Sqlite/SqliteLimitTests.cs |
Uses CompileContext. |
QueryBuilder.Tests/PostgreSql/PostgreSqlLimitTests.cs |
Uses CompileContext. |
QueryBuilder.Tests/Oracle/OracleLimitTests.cs |
Uses CompileContext. |
QueryBuilder.Tests/Oracle/OracleLegacyLimitTests.cs |
Uses CompileContext. |
QueryBuilder.Tests/MySql/MySqlLimitTests.cs |
Uses CompileContext. |
QueryBuilder.Tests/Firebird/FirebirdLimitTests.cs |
Uses CompileContext. |
QueryBuilder.Tests/GeneralTests.cs |
Adds pagination binding-order tests. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| } | ||
|
|
||
| return string.Join(" ", result); | ||
| if (ctx.Buffer.Length > 0 && ctx.Buffer[ctx.Buffer.Length - 1] == ' ') |
Comment on lines
+278
to
+282
| ctx.Write(Wrap(item.Column)); | ||
|
|
||
| if (!item.Values.Any()) | ||
| { | ||
| return item.IsNot ? $"1 = 1 /* NOT IN [empty list] */" : "1 = 0 /* IN [empty list] */"; | ||
| ctx.Write(item.IsNot ? " 1 = 1 /* NOT IN [empty list] */" : " 1 = 0 /* IN [empty list] */"); |
| alias = string.IsNullOrEmpty(alias) ? "" : $" {ColumnAsKeyword}{alias}"; | ||
|
|
||
| combinedQueries.Add(WrapIdentifiers(combineRawClause.Expression)); | ||
| var filterCtx = new CompileContext(ctx.CurrentQuery, parameterPlaceholder, EscapeCharacter); |
Comment on lines
+761
to
+764
| else if (x is OrderBy orderBy) | ||
| { | ||
| var direction = orderBy.Ascending ? "" : " DESC"; | ||
| ctx.Write(Wrap(orderBy.Column)).Write(direction); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Old
SqlResultwas playing multiple roles, as a compilation context, and as a execution result.create a new compilation context
CompileContextthat act as the context when compiling the query, and keepSqlResultfor the final result only.Refactor the compiler to use a light weight Visitor pattern instead of the old string concatenation, leading to faster and cleaner compilation.