drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
23.02k stars 553 forks source link

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

Open tslater opened 1 year ago

tslater commented 1 year ago

What version of drizzle-orm are you using?

0.28.5

What version of drizzle-kit are you using?

0.19.13

Describe the Bug

The mysql2 library parses binary & varbinary columns as Buffer.

They also automatically convert Buffers to hex strings, so passing those in to a query is escaped correctly.

Expected behavior

The type should be Buffer

Environment & setup

Generally

tslater commented 1 year ago

There was a pull request for this, but it has been closed due to complications between the planetscale and mysql2 adapters differing in terms of behavior: https://github.com/drizzle-team/drizzle-orm/pull/425

algora-pbc commented 1 year ago

💎 $200 bounty created by @tslater 👉 To claim this bounty, submit your pull request on Algora 📝 Before proceeding, please make sure you can receive payouts in your country 💵 Payment arrives in your account 2-5 days after the bounty is rewarded 💯 You keep 100% of the bounty award 🙏 Thank you for contributing to drizzle-team/drizzle-orm!

ologbonowiwi commented 11 months ago

There's anyone already working on it?

I would like to help with it 😄

tslater commented 11 months ago

@ologbonowiwi Do you think you can pound through it quickly? I thought there was someone on here that said they wanted to, but I only see it in my email and not here. I wonder if it was deleted? I say go for it since it's been a week and no sign of them.

ologbonowiwi commented 11 months ago

I'm not sure @tslater.

I want to help but I don't know the project internals, so it'll be quite a challenge.

/attempt #1188

ryanagillie commented 11 months ago

@ologbonowiwi Hey! Thanks for sending me a DM on linkedin, I have my github completely muted and missed this.

I had tried getting it working but as in the PR, the mysql2 package (which is API compliant with the mysql package) parses binary and varbinary columns as Buffer while the @planetscale/database parses them as string | null.

I tried playing around to get it to work but ran into the issue that they both rely on the drizzle-orm/mysql-core sub-package (specifically the MySqlVarBinaryBuilderInitial). So changing the column definitions in one changes them in the other.

Life got busy and I converted to neon / postgress in my projects so I abandoned it.

Hope I could help, but this is pretty complicated and I'm not sure how to fix it. Let me know if you need anything else!

ologbonowiwi commented 11 months ago

Thanks for the clarification, @ryanagillie; only this comment helped a lot!

ologbonowiwi commented 7 months ago

The work on #1253 from my side is mostly done, this was the last update from @AndriiSherman on the discord thread.

image

Posting it here so we have the issue updated.

tslater commented 1 month ago

@AndriiSherman any updates?