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

Better type casting of BIT values #2559

Open
sidorares opened this issue Nov 22, 2022 · 3 comments
Open

Better type casting of BIT values #2559

sidorares opened this issue Nov 22, 2022 · 3 comments

Comments

@sidorares
Copy link
Member

see similar discussion in sidorares/node-mysql2#1597

Currently BIT fields are always returned as single byte Buffer:

return parser.parseLengthCodedBuffer();

I think this should be returned as a number. Might be good to coordinate both changes here in mysql2, this is potentially a breaking backwards incompatible change

@dougwilson
Copy link
Member

Good idea. Need to make sure we don't run in to Javascript number issues. The BIT field is up to 64 bits wide and of course a plain javascript number can only be 53 bits wide. Perhaps it would just always return a BigInt?

@sidorares
Copy link
Member Author

Oh, for some reason I assumed it's always just one byte. Not so sure about this change now, really depends on what's the most common use case in real life. If it's actually used as a "bit field" a Buffer might be a good container for it

@dougwilson
Copy link
Member

Gotcha. Yes, I don't personally use the field, so not sure all the uses folks have for it. The field itself comes back as a length-encoded string field over the text protocol and the BIT type in the database can be between 1 and 64 bits. The string contents is just the binary data of the bits, not really much different from like a BINARY field, just that the length is defined in bits instead of bytes. I guess there is probably some kind of storage optimization possible for this but 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants