Skip to content

Refactor compiler to use the Visitor patterns - #787

Open
ahmad-moussawi wants to merge 8 commits into
mainfrom
refactor_compiler
Open

ahmad-moussawi wants to merge 8 commits into
mainfrom
refactor_compiler

Conversation

@ahmad-moussawi

@ahmad-moussawi ahmad-moussawi commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Old SqlResult was playing multiple roles, as a compilation context, and as a execution result.

create a new compilation context CompileContext that act as the context when compiling the query, and keep SqlResult for 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.

Breaking changes:

  • Query.OrderByRandom(string) $\rightarrow$ Query.OrderByRandom(int?).
  • caseSensitive parameters removed from WhereLike, WhereContains, WhereStarts, WhereEnds.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

Comment thread QueryBuilder/Compilers/Compiler.Conditions.cs Outdated
Comment thread QueryBuilder/Compilers/Compiler.Conditions.cs Outdated
Comment thread QueryBuilder/Compilers/Compiler.cs Outdated
Comment thread QueryBuilder/Compilers/Compiler.cs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread QueryBuilder/Compilers/Compiler.cs
Comment thread QueryBuilder/Compilers/MySqlCompiler.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unchecked MySQL seed interpolation and incorrect raw-source binding order in SQL Server joined updates remain unresolved.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread QueryBuilder/Compilers/Compiler.cs
Comment thread QueryBuilder/Compilers/MySqlCompiler.cs Outdated
Ahmad added 2 commits October 19, 2026 07:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The cross-dialect compiler rewrite requires human validation, with unresolved joined-write correctness issues.

2 open issues
2 resolved since last review

Review effort: Balanced

if (hasJoins)
{
wheres = " " + wheres;
ctx.Write($"UPDATE {target} SET {sets} FROM {table}");
Comment on lines +399 to +400
var cleanAlias = alias.Trim().Trim('[', ']', '"', '`');
return WrapValue(cleanAlias);

This branch has not been deployed

No deployments
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