Skip to content

Replace built-in multi query parser with nextras/multi-query-parser#151

Merged
JanTvrdik merged 1 commit intomasterfrom
use-multi-query-parser
Feb 25, 2026
Merged

Replace built-in multi query parser with nextras/multi-query-parser#151
JanTvrdik merged 1 commit intomasterfrom
use-multi-query-parser

Conversation

@JanTvrdik
Copy link
Copy Markdown
Member

Summary

  • Adds nextras/multi-query-parser as a dependency
  • Replaces the hand-rolled 75-line SQL parser in BaseDriver::loadFile() with calls to IMultiQueryParser::parseFile()
  • Adds abstract createMultiQueryParser() to BaseDriver, implemented by MySqlDriver (→ MySqlMultiQueryParser) and PgSqlDriver (→ PostgreSqlMultiQueryParser)
  • Updates unit tests to use the library's parser and adjusted expected values (the library trims leading whitespace/comments from queries)

Test plan

  • All 26 unit tests pass
  • Integration tests with MySQL
  • Integration tests with PostgreSQL

Copilot AI review requested due to automatic review settings February 24, 2026 16:45
@JanTvrdik JanTvrdik force-pushed the use-multi-query-parser branch from 16426f8 to aeddb9e Compare February 24, 2026 16:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the SQL parsing logic by replacing a hand-rolled 75-line SQL parser with the external nextras/multi-query-parser library. The change simplifies the codebase by delegating complex SQL parsing logic to a dedicated library that handles MySQL and PostgreSQL syntax differences, including features like DELIMITER statements, dollar-quoted strings, and comment handling.

Changes:

  • Adds nextras/multi-query-parser (v2.0) as a dependency
  • Introduces abstract createMultiQueryParser() method in BaseDriver, implemented by MySqlDriver and PgSqlDriver with their respective parser classes
  • Simplifies BaseDriver::loadFile() from 75 lines to ~13 lines by delegating to the library's parseFile() method
  • Updates unit tests to mock the new parser method and adjusts expected query values to reflect the library's behavior of trimming leading whitespace/comments

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
composer.json Adds nextras/multi-query-parser version ^2.0 as a required dependency
src/Drivers/BaseDriver.php Removes hand-rolled parser, adds abstract createMultiQueryParser() method, simplifies loadFile() to use library's parser
src/Drivers/MySqlDriver.php Implements createMultiQueryParser() returning MySqlMultiQueryParser instance
src/Drivers/PgSqlDriver.php Implements createMultiQueryParser() returning PostgreSqlMultiQueryParser instance
tests/cases/unit/BaseDriverTest.phpt Updates test mocking to use MySqlMultiQueryParser, adjusts expected values for trimmed whitespace, removes duplicate test case

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…ibrary

The hand-rolled SQL parser in BaseDriver::loadFile() is replaced by the
dedicated nextras/multi-query-parser package, which provides proper
database-specific parsers (MySQL, PostgreSQL) with streaming support.
@JanTvrdik JanTvrdik force-pushed the use-multi-query-parser branch from aeddb9e to 922bdeb Compare February 25, 2026 20:45
@JanTvrdik JanTvrdik merged commit d67d6c9 into master Feb 25, 2026
6 checks passed
@JanTvrdik JanTvrdik deleted the use-multi-query-parser branch February 25, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants