Draft
Conversation
…ith static helpers
… raw, and convenience methods
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
- 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
… built-in implementations
… introduce value objects
…into Builder namespace
…nd new dialect support
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>
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.
No description provided.