{"id":28391417,"url":"https://github.com/shipmonk-rnd/doctrine-hint-driven-sql-walker","last_synced_at":"2025-06-25T21:31:05.305Z","repository":{"id":205308255,"uuid":"711982987","full_name":"shipmonk-rnd/doctrine-hint-driven-sql-walker","owner":"shipmonk-rnd","description":"Doctrine's SqlWalker that allows hooking multiple handlers via -\u003esetHint() while each can edit produced SQL or its part.","archived":false,"fork":false,"pushed_at":"2024-11-12T13:36:41.000Z","size":88,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-31T19:34:44.691Z","etag":null,"topics":["doctrine","orm","querybuilder"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shipmonk-rnd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-30T15:04:34.000Z","updated_at":"2024-11-12T13:36:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"312adfd4-00f0-4b63-b657-7f902fab0b20","html_url":"https://github.com/shipmonk-rnd/doctrine-hint-driven-sql-walker","commit_stats":null,"previous_names":["shipmonk-rnd/doctrine-hint-driven-sql-walker"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/shipmonk-rnd/doctrine-hint-driven-sql-walker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipmonk-rnd%2Fdoctrine-hint-driven-sql-walker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipmonk-rnd%2Fdoctrine-hint-driven-sql-walker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipmonk-rnd%2Fdoctrine-hint-driven-sql-walker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipmonk-rnd%2Fdoctrine-hint-driven-sql-walker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shipmonk-rnd","download_url":"https://codeload.github.com/shipmonk-rnd/doctrine-hint-driven-sql-walker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipmonk-rnd%2Fdoctrine-hint-driven-sql-walker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261955855,"owners_count":23235964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["doctrine","orm","querybuilder"],"created_at":"2025-05-31T09:12:47.324Z","updated_at":"2025-06-25T21:31:05.298Z","avatar_url":"https://github.com/shipmonk-rnd.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## SqlWalker for Doctrine allowing multiple handlers to modify resulting SQL\n\nSince Doctrine's [SqlWalker](https://www.doctrine-project.org/projects/doctrine-orm/en/3.3/cookbook/dql-custom-walkers.html#modify-the-output-walker-to-generate-vendor-specific-sql) serves as a translator from DQL AST to SQL,\nit becomes problematic when you want to alter resulting SQL within multiple libraries by such approach.\nThere just can be only single SqlWalker.\n\nThis library solves this issue, by providing `HintHandler` base class which is designed for SQL modification\nand can be used multiple times in `$queryBuilder-\u003esetHint()`.\n\n### Installation:\n\n```sh\ncomposer require shipmonk/doctrine-hint-driven-sql-walker\n```\n\n### Usage:\n\n```php\n$queryBuilder\n    -\u003esetHint(Query::HINT_CUSTOM_OUTPUT_WALKER, HintDrivenSqlWalker::class)\n    -\u003esetHint(MaxExecutionTimeHintHandler::class, 1000)\n```\n\nWhere `MaxExecutionTimeHintHandler` just extends our `HintHandler` and picks some `SqlNode` to hook to and alters appropriate SQL part:\n\n```php\nclass MaxExecutionTimeSqlWalker extends HintHandler\n{\n\n    public function getNodes(): array\n    {\n        return [SqlNode::SelectClause];\n    }\n\n    public function processNode(\n        SqlNode $sqlNode,\n        string $sql,\n    ): string\n    {\n        // grab the 1000 passed to -\u003esetHint()\n        $milliseconds = $this-\u003egetHintValue();\n\n        // edit SQL as needed\n        return preg_replace(\n            '~^SELECT (.*?)~',\n            \"SELECT /*+ MAX_EXECUTION_TIME($milliseconds) */ \\\\1 \",\n            $sql\n        );\n    }\n```\n\nSqlNode is an enum of all `walkXxx` methods in Doctrine's SqlWalker, so you are able to intercept any part of AST processing the SqlWalker does.\n\n### Limitations\n- Please note that since [doctrine/orm 3.3.0](https://github.com/doctrine/orm/pull/11188), the produced SQL gets finalized with `LIMIT` / `OFFSET` / `FOR UPDATE` after `SqlWalker` processing is done.\n  - Thus, implementors should be aware that those SQL parts can be appended to the SQL after `HintHandler` processing.\n  - This means that e.g. placing a comment at the end of the SQL breaks LIMIT functionality completely\n\n### Implementors\n- [shipmonk/doctrine-mysql-optimizer-hints](https://github.com/shipmonk-rnd/doctrine-mysql-optimizer-hints) (since v2)\n- [shipmonk/doctrine-mysql-index-hints](https://github.com/shipmonk-rnd/doctrine-mysql-index-hints) (since v3)\n\n### Compatibility\n| Version | PHP Compatibility | doctrine/orm |\n|---------| ----------------- |--------------|\n| v1      | 7.2 - 8.3         | 2.x          |\n| v2      | 8.1 - 8.4         | 3.x          |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshipmonk-rnd%2Fdoctrine-hint-driven-sql-walker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshipmonk-rnd%2Fdoctrine-hint-driven-sql-walker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshipmonk-rnd%2Fdoctrine-hint-driven-sql-walker/lists"}