| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
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.
…SwooleExtContainerStub
…sQueryGrammarTest
…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
…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
|
周末处理 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
This PR adds 4 missing Query Builder methods for checking if a JSON path exists:
These methods exist in Laravel but were missing from Hyperf.
Changes
1. New Builder Methods
Added to src/database/src/Query/Builder.php:
2. Grammar Support
Each database has different SQL syntax for this operation:
3. CompilesJsonPaths Trait
Ported Laravel's new CompilesJsonPaths trait to share improved JSON path compilation logic between Query Grammar and Schema Grammar classes.
Why this was needed:
Hyperf's wrapJsonPath (base Grammar) and wrapJsonPathAttributes (Postgres) were outdated and didn't handle array indices in JSON paths. For example, options->languages[0][1] was incorrectly treated as a single quoted key "languages[0][1]" instead of being parsed as "languages"[0][1].
The fix required updating these methods, but they were duplicated across Query Grammar and SQLite Schema Grammar. Laravel solves this with a shared trait.
Changes:
The trait contains:
Test fix:
The existing MySQL test in QueryBuilderTest.php had an incorrect expectation that matched the buggy behavior:
Laravel's test confirms the correct expectation: DatabaseQueryBuilderTest.php:6682-6683
4. PostgreSQL / SQLite Test Structure Fix
The database-pgsql and database-sqlite test files had two problems:
Problem 1: Class names
The old names were not consistent. I renamed them to match Laravel's class names:
I also removed a duplicate test class.
Problem 2: Postgres tests used deprecated Swoole extension
The main ContainerStub and DatabasePostgresBuilderTest test files used the deprecated pgsql-swoole driver:
Hyperf now uses PDO for PostgreSQL. The tests only run on Swoole < 6.0.
Solution:
Renamed old files to clearly show they test the deprecated extension:
Created new files for PDO driver:
Files Changed
New trait + JSON path fixes:
New Builder methods:
Tests: