Skip to content

fix(mysql): type binary/varbinary as Buffer instead of string#5605

Open
manja316 wants to merge 1 commit intodrizzle-team:mainfrom
manja316:fix/mysql-binary-buffer-type
Open

fix(mysql): type binary/varbinary as Buffer instead of string#5605
manja316 wants to merge 1 commit intodrizzle-team:mainfrom
manja316:fix/mysql-binary-buffer-type

Conversation

@manja316
Copy link
Copy Markdown

@manja316 manja316 commented Apr 6, 2026

Summary

MySQL binary and varbinary columns store raw byte data. The mysql2 driver correctly parses these as Buffer, but drizzle-orm was converting them to strings via .toString(), losing binary semantics.

  • Changes dataType from 'string' to 'buffer' for MySqlBinary and MySqlVarBinary
  • Changes data and driverParam types from string to Buffer
  • Updates mapFromDriverValue to return Buffer directly instead of converting to string
  • Follows the same pattern as SQLiteBlobBuffer which correctly uses dataType: 'buffer'

Breaking Change

This is a type-level breaking change. Users who relied on binary()/varbinary() returning string will need to update their code:

// Before
const row = await db.select().from(table);
row.binaryCol; // string

// After
const row = await db.select().from(table);
row.binaryCol; // Buffer
row.binaryCol.toString(); // string (if needed)

Test Plan

  • Type tests pass (pnpm test:types in drizzle-orm)
  • Updated type test defaults from '' to Buffer.from('')
  • Integration tests (require MySQL instance)

Note

The same issue exists in singlestore-core columns — left as a follow-up to keep this PR focused.

Fixes #1188

/claim #1188

…ring

MySQL binary and varbinary columns store raw byte data. The mysql2 driver
correctly parses these as Buffer, but drizzle-orm was converting them to
strings via .toString(), losing the binary semantics.

This change:
- Updates dataType from 'string' to 'buffer' for both column types
- Updates data and driverParam types from string to Buffer
- Changes mapFromDriverValue to return Buffer directly instead of
  converting to string
- Updates type tests to use Buffer.from('') for defaults

This follows the same pattern used by SQLite's blob buffer column type
(SQLiteBlobBuffer) which correctly uses dataType: 'buffer'.

Fixes drizzle-team#1188

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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