Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cast logic #174

Merged
merged 10 commits into from
Apr 25, 2024
Merged

Fix cast logic #174

merged 10 commits into from
Apr 25, 2024

Conversation

mattrobenolt
Copy link
Member

@mattrobenolt mattrobenolt commented Apr 25, 2024

There's a lot to unpack here, but the tl;dr is to refer to the charset ultimately to determine if the data is binary, or non-binary which is always UTF-8.

This fixes behavior around CHAR/TEXT fields with a binary collation, being surfaces as BINARY/BLOB types by MySQL.

For all intents and purposes, BLOB/BINARY/CHAR/TEXT are all effectively identical and interchangeable, the only differentiator is their charset. Either they are a binary charset, or they are encoded as UTF-8.

This behavior seems to differ slightly from vanilla MySQL and is specific to potentially a bug in Vitess, but this default is much safer for future proofing if we fix things there.

Fixes #169 #171

__tests__/index.test.ts Outdated Show resolved Hide resolved
src/text.ts Outdated Show resolved Hide resolved
There's a lot to unpack here, but the tl;dr is to refer to the charset
ultimately to determine if the data is UTF8, if it is, we can decode it
to a UTF8 string.

This fixes behavior around CHAR/TEXT fields with a binary collation,
being surfaces as BINARY/BLOB types by MySQL.

For all intents and purposes, BLOB/BINARY/CHAR/TEXT are all effectively
identical and interchangeable, the only differentiator is their charset.
Either they are a UTF-8 charset, or a binary charset or some other
charset.

Fixes #169
@mattrobenolt mattrobenolt force-pushed the fix-cast branch 2 times, most recently from 8b95a38 to b5c7ed8 Compare April 25, 2024 20:20
__tests__/index.test.ts Outdated Show resolved Hide resolved
__tests__/index.test.ts Outdated Show resolved Hide resolved
@@ -13,6 +16,13 @@ const config = {
fetch
}

function uint8ArrayFromHex(text: string): Uint8Array {
Copy link
Member Author

Choose a reason for hiding this comment

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

This helper was nice becuase it makes it easier to copy/paste the hex output from mysql CLI for it's rendering of binary data. Figured I'd like to have a source of truth to copy/paste from rather than hand writing each byte in a Uint8Array.

src/cast.ts Outdated Show resolved Hide resolved
src/cast.ts Outdated Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
__tests__/cast.test.ts Outdated Show resolved Hide resolved
@ayrton ayrton enabled auto-merge (squash) April 25, 2024 21:44
@mattrobenolt
Copy link
Member Author

@ayrton I can't approve your changes since I created the PR, but everything I brought up was addressed, looks good to me.

@ayrton ayrton merged commit ac5bdc4 into main Apr 25, 2024
5 checks passed
@ayrton ayrton deleted the fix-cast branch April 25, 2024 21:58
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.

UUIDs Get Returned Incorrectly
2 participants