Skip to content

Conversation

@tianzhou
Copy link
Contributor

@tianzhou tianzhou commented Nov 2, 2025

No description provided.

Copilot AI review requested due to automatic review settings November 2, 2025 17:10
Copy link
Contributor

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 PR modifies the MySQL and MariaDB connectors to use dedicated connections from the pool for SQL execution, ensuring session consistency for session-specific features like LAST_INSERT_ID(). Previously, using pool.query() directly could result in different connections being used for consecutive queries, breaking session-dependent functionality.

Key changes:

  • Acquires a dedicated connection via pool.getConnection() before executing queries
  • Ensures connection is properly released back to the pool in a finally block
  • Updates comments to reflect the use of dedicated connections instead of pool-level queries

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/connectors/mysql/index.ts Modified executeSQL to use dedicated connections with proper cleanup, also removed trailing whitespace
src/connectors/mariadb/index.ts Modified executeSQL to use dedicated connections with proper cleanup, also removed trailing whitespace

Fixed session consistency issues causing intermittent test failures with
LAST_INSERT_ID(). The root causes were:

1. Separate executeSQL() calls getting different connections from pool
2. Multi-statement results including metadata objects from INSERT/UPDATE/DELETE

Changes:
- Updated connectors to use explicit connection acquisition (pool.getConnection)
- Enhanced multi-statement result handling to filter out metadata objects
- Modified tests to combine INSERT and SELECT into single executeSQL call
- Ensures all SQL in one call uses same connection for session-specific features

Tests now pass consistently (32/32 MariaDB, 30/30 MySQL verified across
multiple runs).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@tianzhou tianzhou requested a review from Copilot November 2, 2025 17:27
Copy link
Contributor

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

tianzhou and others added 2 commits November 2, 2025 09:32
…detection

Replaced the fragile `constructor.name === 'ResultSetHeader'` check with
robust property-based type detection using specific properties like
'affectedRows', 'insertId', and 'fieldCount'. This prevents potential
breakage from minification or bundling tools that can mangle constructor
names.

The new approach:
- Checks for ResultSetHeader-specific properties instead of constructor name
- More resilient to code transformations
- Maintains the same functionality and test coverage

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Created a shared utility to handle multi-statement SQL result parsing,
eliminating code duplication between MariaDB and MySQL connectors.

The new utility provides:
- Consistent detection of metadata objects vs row arrays
- Unified handling of single and multi-statement results
- Property-based type checking (no fragile constructor.name checks)
- Clear, well-documented logic for both driver behaviors

Changes:
- Added src/utils/multi-statement-result-parser.ts with shared parsing logic
- Updated MariaDB connector to use parseQueryResults()
- Updated MySQL connector to use parseQueryResults()
- Reduced duplicated code by 70 lines while adding 93 lines of reusable utility

Benefits:
- Single source of truth for result parsing logic
- Easier to maintain and test
- More resilient to driver API changes
- Consistent behavior across both connectors

All tests pass (32 MariaDB + 30 MySQL = 62 tests).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@tianzhou tianzhou requested a review from Copilot November 2, 2025 17:40
Copy link
Contributor

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@tianzhou tianzhou merged commit b60998a into main Nov 2, 2025
8 checks passed
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