feat: Port `whereJsonContainsKey` methods + `CompilesJsonPaths` from Laravel by binaryfire · Pull Request #7699 · hyperf/hyperf

added 10 commits

January 18, 2026 14:55
Add whereJsonContainsKey, orWhereJsonContainsKey, whereJsonDoesntContainKey,
and orWhereJsonDoesntContainKey methods to Query Builder.
Add compileJsonContainsKey method to base Grammar (throws by default) and
implement for MySQL, PostgreSQL, and SQLite drivers.
Add tests for MySQL, PostgreSQL, and SQLite grammars covering
whereJsonContainsKey, orWhereJsonContainsKey, whereJsonDoesntContainKey,
and orWhereJsonDoesntContainKey methods.
- Rename ContainerStub to SwooleExtContainerStub (tests deprecated extension)
- Rename DatabasePostgresBuilderTest to DatabasePostgresSwooleExtQueryBuilderTest
- Create new ContainerStub for PDO driver
- Create new DatabasePostgresQueryBuilderTest for PDO driver tests
- Rename DatabaseSQLiteQueryGrammarTest to DatabaseSQLiteQueryBuilderTest

The old names were inconsistent with the database package naming.
Schema Builder tests use "BuilderTest", Query Builder tests use "QueryBuilderTest".
Rename query builder test classes to match SchemaBuilderTest naming:
- DatabasePostgresQueryBuilderTest → QueryBuilderTest
- DatabasePostgresSwooleExtQueryBuilderTest → SwooleExtQueryBuilderTest
- DatabaseSQLiteQueryBuilderTest → QueryBuilderTest
…BuilderTest

Consistent with database and database-pgsql packages.

@binaryfire binaryfire changed the title feat: Port whereJsonContainsKey methods from Laravel + fix PostgreSQL / SQLite test structure feat: Port whereJsonContainsKey methods from Laravel + fix wrapJsonPath

Jan 19, 2026
…dex support

- Update Grammar::wrapJsonPath() + add wrapJsonPathSegment() to properly parse
  array indices (e.g., `foo[0]` → `"foo"[0]` instead of `"foo[0]"`)
- Update PostgresGrammar::wrapJsonPathAttributes() + add parseJsonPathArrayKeys()
- Fix incorrect test expectation for array indices to match Laravel behavior
- Add array index tests for MySQL, PostgreSQL, and SQLite

Reference: laravel/framework DatabaseQueryBuilderTest.php:6682-6683

@binaryfire

@binaryfire binaryfire changed the title feat: Port whereJsonContainsKey methods from Laravel + fix wrapJsonPath feat: Port whereJsonContainsKey methods + CompilesJsonPaths from Laravel

Jan 19, 2026
…pilation

Port Laravel's CompilesJsonPaths trait pattern to eliminate code duplication
between Query Grammar and Schema Grammar classes.

- Create CompilesJsonPaths trait with wrapJsonFieldAndPath, wrapJsonPath,
  and wrapJsonPathSegment methods
- Use trait in Query Grammar (removes 51 lines of duplicated code)
- Use trait in Schema Grammar base class
- Remove duplicated methods from SQLite Schema Grammar (46 lines)
- Remove unused Str import from SQLite Schema Grammar
…ssing tests

- Fix compileJsonUpdateColumn to use wrapJsonPathAttributes for proper
  array index parsing in UPDATE queries
- Cast $i to int in compileJsonContainsKey for strict_types compatibility
- Add testMySqlUpdateWrappingJsonPathArrayIndex test
- Add testJsonPathEscaping test
- Add testPostgresUpdateWrappingJsonPathArrayIndex test
- Add testSQLiteUpdateWrappingJsonPathArrayIndex test
- Add PostgreSQL negative array index tests ([-1]) for whereJsonContainsKey
  and whereJsonDoesntContainKey

limingxinleo