Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
e43e1a9
(feat): Add Compiler interface and Query::compile() visitor method
abnegate Mar 4, 2026
57bb071
(feat): Add SQL Builder with fluent API and parameterized queries
abnegate Mar 4, 2026
2a388f9
(docs): Update README with Compiler and Builder examples
abnegate Mar 4, 2026
d8c3af9
(feat): Add aggregation, join, distinct, union, and raw query types w…
abnegate Mar 4, 2026
d0094ba
(feat): Add Builder support for aggregations, joins, distinct, union,…
abnegate Mar 4, 2026
8ecb2b8
(test): Add tests for aggregations, joins, distinct, union, raw, and …
abnegate Mar 4, 2026
8febdbe
(docs): Add documentation for aggregations, joins, distinct, union, r…
abnegate Mar 4, 2026
14c655c
fix: address code review findings
abnegate Mar 4, 2026
96ae766
fix: address code review findings
abnegate Mar 4, 2026
fb06eb3
fix: address cycle 2 code review findings
abnegate Mar 4, 2026
4330afd
(feat): Add hook interface system with FilterHook, AttributeHook, and…
abnegate Mar 4, 2026
57b17ca
(refactor): Replace closure-based extension API with hook system in B…
abnegate Mar 4, 2026
5a5294b
(docs): Update README with hook system documentation
abnegate Mar 4, 2026
b47d9d3
(refactor): Extract Method, OrderDirection, CursorDirection enums and…
abnegate Mar 5, 2026
1c5afd6
(refactor): Move BuildResult, UnionClause, Condition, GroupedQueries …
abnegate Mar 5, 2026
4b4d14f
(chore): Add .idea to gitignore
abnegate Mar 10, 2026
882c067
(refactor): Add QuotesIdentifiers trait, exceptions, and enum updates
abnegate Mar 10, 2026
8911cb7
(refactor): Reorganize hook system into Attribute, Filter, and Join n…
abnegate Mar 10, 2026
b18b9f5
(feat): Add abstract Builder with feature interfaces, Case builder, a…
abnegate Mar 10, 2026
5880814
(feat): Add MySQL, PostgreSQL, and ClickHouse dialect builders
abnegate Mar 10, 2026
741593a
(feat): Add Schema builder layer with MySQL, PostgreSQL, and ClickHou…
abnegate Mar 10, 2026
1699453
(test): Add comprehensive tests for builders, schema, hooks, and exce…
abnegate Mar 10, 2026
51f467e
(docs): Update README with builder, schema, and hook documentation
abnegate Mar 10, 2026
aced40d
(refactor): Refine builder APIs with enums, value objects, and strict…
abnegate Mar 10, 2026
6d39bd0
(refactor): Refine schema APIs with enums and strict types
abnegate Mar 10, 2026
afa47a7
(test): Add binding count assertions, exact query tests, and fix type…
abnegate Mar 10, 2026
54cc13f
(test): Add Docker integration tests for MySQL, PostgreSQL, and Click…
abnegate Mar 10, 2026
1c74748
(chore): Add CLAUDE.md project coding rules
abnegate Mar 10, 2026
b563fb8
(test): Add advanced exact query assertions for all dialects
abnegate Mar 10, 2026
4535886
(feat): Add schema support for strict enums, partitions, comments, se…
abnegate Mar 12, 2026
37a2a77
(refactor): Remove Permission hook from library and add Write hook in…
abnegate Mar 12, 2026
692477c
(feat): Add builder features for joins, windows, merge, aggregates, a…
abnegate Mar 12, 2026
08d5692
Ignore
abnegate Mar 12, 2026
d65c06e
(feat): Add MongoDB builder and schema dialect
abnegate Mar 12, 2026
89da709
(feat): Add query parser for SQL and MongoDB dialects
abnegate Mar 12, 2026
53e35dc
(test): Add tests for MongoDB, MariaDB, SQLite, and query parser
abnegate Mar 12, 2026
9882ff2
(test): Expand unit tests for MySQL, PostgreSQL, and ClickHouse
abnegate Mar 12, 2026
6f4ccfd
(fix): Update integration tests for ClickHouse and PostgreSQL
abnegate Mar 12, 2026
f1c3d52
(chore): Add MongoDB CI service and update dependencies
abnegate Mar 12, 2026
fe50ab2
(docs): Update README with new dialects, parser, and feature docs
abnegate Mar 12, 2026
cb4910c
(style): Rename parser test methods to camelCase
abnegate Mar 12, 2026
c0bcd53
(feat): Add new aggregates, HAVING expressions, and SQL builder enhan…
abnegate Mar 24, 2026
1ec165f
(feat): Add ClickHouse-specific builder features
abnegate Mar 24, 2026
ff2b8bb
(feat): Add MongoDB-specific builder features
abnegate Mar 24, 2026
f871339
(feat): Add SQL tokenizer and AST node hierarchy
abnegate Mar 24, 2026
4e0f32d
(feat): Add recursive-descent SQL parser for AST construction
abnegate Mar 24, 2026
b3243cf
(feat): Add AST serializer and fix parser review issues
abnegate Mar 24, 2026
5f5ae07
(feat): Add dialect-specific tokenizers and serializers
abnegate Mar 24, 2026
36641e3
(feat): Add AST visitor pattern with Walker and built-in visitors
abnegate Mar 24, 2026
188da99
(feat): Add Builder ↔ AST bidirectional conversion
abnegate Mar 24, 2026
4d19662
(style): Fix lint, static analysis, and review issues
abnegate Mar 24, 2026
7f6ab43
(docs): Mark tokenizer/AST implementation plan as complete
abnegate Mar 24, 2026
b18176e
(refactor): Rename abbreviated AST types to full names with namespace…
abnegate Mar 24, 2026
553f540
(refactor): Move SelectStatement and WindowSpecification to sub-names…
abnegate Mar 24, 2026
3f13d24
(refactor): Move WindowDefinition, CteDefinition, FunctionCall to sub…
abnegate Mar 24, 2026
461c6e2
fix: address code review findings
abnegate Mar 24, 2026
342c994
fix: protect double-quoted identifiers in MySQL hash comment replacement
abnegate Mar 24, 2026
9852c14
(test): Improve AST and Tokenizer test coverage to 90%
abnegate Mar 24, 2026
4050847
(feat): Rename BuildResult to Plan and add executor pattern
abnegate Mar 26, 2026
3f57d89
(test): Update tests to use Plan instead of BuildResult
abnegate Mar 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .claude/plans/PLAN-sql-tokenizer-ast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Implementation Plan: SQL Tokenizer & AST

**Status:** Complete
**Created:** 2026-03-24
**Completed:** 2026-03-24
**Description:** Add a tokenizer, parser, AST node hierarchy, serializer, visitor pattern, and Builder integration for SQL SELECT queries. Supports per-dialect tokenization/serialization for MySQL, PostgreSQL, ClickHouse, SQLite, and MariaDB. Enables round-trip: SQL string -> tokens -> AST -> modify/validate -> SQL string, plus AST <-> Builder conversion.

## Phases

### Phase 1: Token Types & Base Tokenizer
- **Status:** [x] Complete

### Phase 2: AST Node Hierarchy
- **Status:** [x] Complete

### Phase 3: Base SQL Parser (Tokens -> AST)
- **Status:** [x] Complete

### Phase 4: Base SQL Serializer (AST -> SQL)
- **Status:** [x] Complete

### Phase 5: Dialect-Specific Tokenizers & Serializers
- **Status:** [x] Complete

### Phase 6: Visitor Pattern for AST Modification & Validation
- **Status:** [x] Complete

### Phase 7: Builder <-> AST Integration
- **Status:** [x] Complete

## Progress Log

### Phase 1 - f871339
- **Tests added:** 42 (35 initial + 7 review fixes)
- **Files:** TokenType.php, Token.php, Tokenizer.php, TokenizerTest.php
- **Review issues fixed:** C1 (block comment bug), C2 (unknown chars), W1 (backslash escapes), W2 (scientific notation), W3 (quoted identifier escapes), W5 (aggregate function casing), W6 (keyword map constant)

### Phase 2 - f871339
- **Tests added:** 27
- **Files:** Expr.php, 22 AST node classes, SelectStatement.php, NodeTest.php

### Phase 3 - 4e0f32d
- **Tests added:** 52
- **Files:** Parser.php, ParserTest.php
- **Review issues fixed:** C1 (FILTER clause stored), C2 (:: cast in parseUnary), C3 (Star schema), C4 (inColumnList reset)

### Phase 4 - b3243cf
- **Tests added:** 62
- **Files:** Serializer.php, SerializerTest.php

### Phase 5 - 5f5ae07
- **Tests added:** 16
- **Files:** 5 tokenizer subclasses, 5 serializer subclasses, 6 test files

### Phase 6 - 36641e3
- **Tests added:** 17
- **Files:** Visitor.php, Walker.php, TableRenamer.php, ColumnValidator.php, FilterInjector.php, VisitorTest.php

### Phase 7 - 188da99
- **Tests added:** 40
- **Files:** Builder.php (modified), BuilderIntegrationTest.php

### Lint/Static Analysis - 4d19662
- **Files changed:** 43 (formatting + type fixes)

## Final Summary

### Tests Added
- 256 new tests total
- 42 tokenizer tests
- 27 AST node tests
- 52 parser tests
- 62 serializer tests
- 16 dialect tokenizer/serializer tests
- 17 visitor tests
- 40 builder integration tests

### Files Changed
- 55 files created, 3 files modified

### Commits
- f871339 - Token types, tokenizer, AST nodes
- 4e0f32d - Recursive-descent parser
- b3243cf - Serializer + parser review fixes
- 5f5ae07 - Dialect tokenizers/serializers
- 36641e3 - Visitor pattern
- 188da99 - Builder <-> AST integration
- 4d19662 - Lint and static analysis fixes

### Verification
- [x] All 4045 tests pass
- [x] Lint passes (Pint)
- [x] Static analysis passes (PHPStan level max)
- [x] No TODOs remaining
- [x] Plan file complete
75 changes: 75 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Integration Tests

on:
push:
branches: [main]
pull_request:

jobs:
integration:
runs-on: ubuntu-latest

services:
mysql:
image: mysql:8.4
ports:
- 13306:3306
env:
MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: query_test
options: >-
--health-cmd="mysqladmin ping -h localhost"
--health-interval=10s
--health-timeout=5s
--health-retries=5

postgres:
image: postgres:16
ports:
- 15432:5432
env:
POSTGRES_PASSWORD: test
POSTGRES_DB: query_test
options: >-
--health-cmd="pg_isready"
--health-interval=10s
--health-timeout=5s
--health-retries=5

clickhouse:
image: clickhouse/clickhouse-server:24
ports:
- 18123:8123
- 19000:9000
env:
CLICKHOUSE_DB: query_test
options: >-
--health-cmd="wget --spider -q http://localhost:8123/ping"
--health-interval=10s
--health-timeout=5s
--health-retries=5

mongodb:
image: mongo:7
ports:
- 27017:27017
options: >-
--health-cmd="mongosh --eval 'db.runCommand({ping:1})'"
--health-interval=10s
--health-timeout=5s
--health-retries=5

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: pdo, pdo_mysql, pdo_pgsql, mongodb

- name: Install dependencies
run: composer install --no-interaction --prefer-dist

- name: Run integration tests
run: composer test:integration
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.phpunit.result.cache
composer.phar
/vendor/
.idea
coverage
coverage.xml
.DS_Store
4 changes: 4 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Project Rules

- Never add decorative section-style comment headers (e.g. `// ==================`, `// ----------`, `// ~~~~` or similar). Use plain single-line comments only when necessary.
- Always use imports (`use` statements) instead of fully qualified class names in test files and source code.
Loading
Loading