fix(mysql): type binary/varbinary as Buffer instead of string#5605
Open
manja316 wants to merge 1 commit intodrizzle-team:mainfrom
Open
fix(mysql): type binary/varbinary as Buffer instead of string#5605manja316 wants to merge 1 commit intodrizzle-team:mainfrom
manja316 wants to merge 1 commit intodrizzle-team:mainfrom
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MySQL
binaryandvarbinarycolumns store raw byte data. Themysql2driver correctly parses these asBuffer, but drizzle-orm was converting them to strings via.toString(), losing binary semantics.dataTypefrom'string'to'buffer'forMySqlBinaryandMySqlVarBinarydataanddriverParamtypes fromstringtoBuffermapFromDriverValueto returnBufferdirectly instead of converting to stringSQLiteBlobBufferwhich correctly usesdataType: 'buffer'Breaking Change
This is a type-level breaking change. Users who relied on
binary()/varbinary()returningstringwill need to update their code:Test Plan
pnpm test:typesin drizzle-orm)''toBuffer.from('')Note
The same issue exists in
singlestore-corecolumns — left as a follow-up to keep this PR focused.Fixes #1188
/claim #1188