Skip to content

fix(mysql): preserve buffers for binary and varbinary - #6174

Open
zubairz4far wants to merge 9 commits into
drizzle-team:mainfrom
zubairz4far:fix/mysql-binary-buffer-1188
Open

fix(mysql): preserve buffers for binary and varbinary#6174
zubairz4far wants to merge 9 commits into
drizzle-team:mainfrom
zubairz4far:fix/mysql-binary-buffer-1188

Conversation

@zubairz4far

@zubairz4far zubairz4far commented Aug 24, 2026

Copy link
Copy Markdown

Fixes #1188

/claim #1188

Summary

  • Type MySQL binary and varbinary columns as Buffer instead of string.
  • Preserve Buffer values returned by mysql2.
  • Normalize binary Uint8Array values to Buffer without changing bytes.
  • Keep accepting legacy string driver values and string SQL defaults for backwards compatibility.
  • Add focused runtime/type tests plus mysql2 and PlanetScale round-trip integration coverage.

Why Buffer by default is viable now

The original direct-Buffer attempt in #425 was closed for one specific reason: mysql2 returned Buffer, while the PlanetScale driver returned strings. That made one shared MySQL column type inconsistent across adapters at the time.

Current @planetscale/database no longer has that blocker:

Buffer is a Uint8Array, so binary data can stay binary through both current mysql2 and PlanetScale paths. Drizzle normalizes a PlanetScale Uint8Array to Buffer without a UTF-8 string round-trip.

Historical review context

#425 was also explicitly asked to add runtime insert/select integration coverage for these columns. This PR now includes that exact evidence for both adapters, using non-UTF-8 bytes (00 ff 80 31) so a lossy string conversion cannot pass unnoticed.

The later direct-Buffer work in #1253 reached a maintainer comment that it “looks good to be merged” before stalling on signed commits and eventually being closed. The adapter behavior that made the older work difficult is what the current PlanetScale implementation has since changed.

Compatibility

Application/select/insert data is inferred as Buffer, matching binary semantics. Existing schema code that uses string SQL defaults such as binary(...).default('') remains accepted through a narrow builder override, so this fix does not require rewriting those default declarations.

Verification

  • Reproduced the current lossy mapping with non-UTF-8 bytes (00 ff 80 31).
  • Added focused mapping tests for mysql2 Buffer, binary-adapter Uint8Array, and legacy string values.
  • Added type-level assertions that binary/varbinary select and insert data infer as Buffer while string defaults remain accepted.
  • Added mysql2 and PlanetScale insert/select round-trip integration tests with the same non-UTF-8 bytes.
  • Changed TypeScript sources passed the available syntax/override-signature checks.

Upstream Actions are currently action_required with no jobs started, so the repository’s first-time-contributor workflow approval is still required before the integration/CI jobs can execute.

@zubairz4far
zubairz4far force-pushed the fix/mysql-binary-buffer-1188 branch from eeb5736 to b786252 Compare August 24, 2026 18:47
@zubairz4far zubairz4far reopened this Aug 24, 2026
@zubairz4far
zubairz4far marked this pull request as ready for review August 24, 2026 18:57

@zubairz4far zubairz4far left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The PR is ready for review. The upstream CodeQL and Release Router runs are currently gated as action_required with no jobs started, so a maintainer workflow approval is needed before those checks can execute. The regression/type coverage is included in the PR.

Copy link
Copy Markdown
Author

Added adapter-level regression coverage for the historical blocker: both mysql2 and the current @planetscale/database path now have dedicated round-trip tests using non-UTF-8 bytes (00 ff 80 31). Current PlanetScale casts binary fields to Uint8Array, which Drizzle normalizes to Buffer, so the old string-vs-Buffer adapter mismatch no longer describes the current driver behavior. The latest Actions runs are still action_required with no jobs started, so these tests are queued behind maintainer workflow approval.

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.

[BUG]: MySQL2 binary/varbinary types are incorrectly typed as strings instead of buffers

1 participant