Skip to content

Feat builder#2

Draft
abnegate wants to merge 60 commits intomainfrom
feat-builder
Draft

Feat builder#2
abnegate wants to merge 60 commits intomainfrom
feat-builder

Conversation

@abnegate
Copy link
Member

@abnegate abnegate commented Mar 4, 2026

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 550a4101-07c3-4838-8fd9-5a84b0ecb557

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-builder

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

abnegate and others added 22 commits March 5, 2026 10:10
- Fix compileIn/compileNotIn to return `1 = 0` / `1 = 1` for empty arrays instead of invalid `IN ()` / `NOT IN ()`
- Fix NOT MATCH() syntax: wrap in parentheses for valid MySQL (`NOT (MATCH(...) AGAINST(?))`)
- Fix toRawSql SQL injection: escape single quotes in string bindings
- Fix toRawSql corruption: use substr_replace instead of preg_replace to avoid `?` and `$` in values corrupting output
- Fix page(0, n) producing negative offset: clamp to max(0, ...)
- Guard compileLogical/compileExists/compileNotExists against empty arrays producing bare `()`
- Simplify null tracking in compileIn/compileNotIn with boolean flag

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix dotted identifier wrapping (users.id → `users`.`id`)
- Escape wrap character in identifiers to prevent SQL injection
- Wrap _cursor column in identifier quotes
- Return 1=1 for empty raw SQL to prevent invalid WHERE clauses
- Treat COUNT('') as COUNT(*)
- Only emit OFFSET when LIMIT is present
- Escape LIKE metacharacters (% and _) in user input
- Validate JOIN operator against allowlist
- Fix condition provider binding order mismatch with cursor
- Wrap UNION queries in parentheses for correct precedence
- Validate ClickHouse SAMPLE fraction range (0,1)
- Use explicit map for aggregate SQL function names
- Escape backslashes in LIKE pattern values
abnegate and others added 30 commits March 12, 2026 17:01
Introduce a character-by-character SQL tokenizer that lexes SQL strings
into typed tokens (keywords, identifiers, literals, operators,
placeholders, comments) with dialect-extensible quoting. Add a complete
AST node hierarchy with typed readonly classes for expressions
(ColumnRef, Literal, BinaryExpr, FunctionCall, CaseExpr, WindowExpr,
etc.), clauses (JoinClause, OrderByItem, CteDefinition, etc.), and
SelectStatement with immutable modification via with().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implement a recursive-descent parser that converts filtered token
streams into SelectStatement AST nodes. Handles full SELECT query
syntax including CTEs, DISTINCT, column aliases, JOINs (all types),
WHERE/HAVING with proper operator precedence (OR < AND < NOT <
comparisons < IS/IN/BETWEEN/LIKE < arithmetic < unary), GROUP BY,
ORDER BY with NULLS positioning, LIMIT/OFFSET, FETCH FIRST, window
functions, CASE expressions, CAST, subqueries, and placeholders.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add SQL serializer that converts AST nodes back to SQL strings with
operator-precedence-aware parenthesization and backtick quoting.
Fix critical parser issues: FILTER clause now stored on FunctionCall,
:: cast operator works at all precedence levels via parseUnary,
schema.table.* preserves schema in Star node, inColumnList reset on
parse(). Add FILTER property to FunctionCall and schema to Star.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add MySQL (with # comment support), PostgreSQL (double-quote quoting,
@>/<@/<=>/<=>/vector operators), ClickHouse, SQLite, and MariaDB
tokenizer and serializer subclasses. Each overrides identifier quoting
and dialect-specific syntax as needed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add Visitor interface and depth-first Walker for AST traversal and
transformation. Include three built-in visitors: TableRenamer (renames
tables in FROM/JOIN/ColumnRef/Star), ColumnValidator (validates column
names against an allow-list), and FilterInjector (injects WHERE
conditions, ANDing with existing clauses). Visitors compose
sequentially and recurse into subqueries and CTEs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add toAst() and fromAst() methods to the base Builder class enabling
round-trip conversion between the fluent Builder API and the AST.
toAst() maps Builder state (table, columns, filters, joins, aggregates,
ordering, groupBy, having, limit, offset, CTEs) to SelectStatement
nodes. fromAst() reconstructs a Builder from an AST, mapping simple
expression patterns back to Query objects and falling back to
Query::raw() for complex expressions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Auto-format with Pint, fix PHPStan level-max errors in Builder AST
methods (type narrowing for Literal values, safe casts for mixed types),
fix Parser dead-code warning by using local variables in
parseIdentifierExpr, remove unused method in PostgreSQLTest, add
PHPDoc type annotations to SelectStatement::with().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… organization

Reorganize AST expression types into Expression\ sub-namespace:
BinaryExpr → Expression\Binary, UnaryExpr → Expression\Unary,
InExpr → Expression\In, BetweenExpr → Expression\Between,
ExistsExpr → Expression\Exists, CaseExpr → Expression\Conditional,
CastExpr → Expression\Cast, AliasedExpr → Expression\Aliased,
SubqueryExpr → Expression\Subquery, WindowExpr → Expression\Window,
CaseWhen → Expression\CaseWhen.

Reorganize reference types into Reference\ sub-namespace:
ColumnRef → Reference\Column, TableRef → Reference\Table.

Rename remaining abbreviated types: Expr → Expression (interface),
WindowSpec → WindowSpecification.

Rename methods and variables to use full names throughout:
serializeExpr → serializeExpression, visitExpr → visitExpression,
walkExpr → walkExpression, $expr → $expression, $ref → $reference,
$spec → $specification.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…paces

SelectStatement → Statement\Select, WindowSpecification →
Specification\Window. Files importing both Expression\Window and
Specification\Window use the alias WindowSpecification to avoid
name conflicts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…-namespaces

WindowDefinition → Definition\Window, CteDefinition → Definition\Cte,
FunctionCall → Call\Func (Function is a PHP reserved word). Files
importing multiple Window types use aliases to avoid conflicts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Preserve column aliases in fromAst() round-trip conversion
- Fix cross-dialect serialization by adding createAstSerializer() override point
- Override in PostgreSQL and SQLite builders for correct quoting
- Replace fully qualified class names with use imports in 5 files
- Remove dead $hasSign variable in Tokenizer
- Cache token count in Parser for performance
- Document FilterInjector subquery behavior

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Skip # characters inside double-quoted identifiers in
replaceHashComments to prevent corruption when ANSI_QUOTES mode
is enabled or mixed-dialect SQL is processed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add SQLite tokenizer and serializer tests. Expand MySQL tokenizer
tests covering all replaceHashComments branches (strings, backticks,
double-quotes, escapes, multiple comments, EOF). Add Walker tests
for Cast, Between, Conditional, Exists, Window, Subquery expressions,
FunctionCall filters, WindowDefinitions, and OrderBy with nulls.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant