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
21.69k stars 493 forks source link

[BUG]: insert().values().execute() returns different value between planetscale mysql2 #816

Open SamyPesse opened 1 year ago

SamyPesse commented 1 year ago

What version of drizzle-orm are you using?

0.27.0

What version of drizzle-kit are you using?

No response

Describe the Bug

The following code:

const result = await database
            .insert(table)
            .values({ ... })
            .execute();

returns different result between drizzle-orm/mysql2 and drizzle-orm/planetscale-serverless.

With drizzle-orm/mysql2, result is an array and doesn't match the typescript definition:

[
      ResultSetHeader {
        fieldCount: 0,
        affectedRows: 1,
        insertId: 1110,
        info: '',
        serverStatus: 3,
        warningStatus: 0
      },
      undefined
]

When using drizzle-orm/planetscale-serverless, accesing result.insertId works directly.

Expected behavior

Both should return the same thing, probably ExecutedQuery or ResultSetHeader

Environment & setup

No response

AndriiSherman commented 11 months ago

on insert, we are returning the same object that is returned from a driver. As long as mysql2 is different from database-js it will have a different API for insert/update/delete data returned

But I agree that we need to unify those and return them all in 1 format. I'll mark this issue as improvement

qw-in commented 2 months ago

This certainly tripped me up! Was also struggling to figure out why insertId is typed as a string. Some small tweaks seem like they'd make drizzle + planetscale a bit more ergonomic.

Maybe I'll take a crack at it at some point if there is still interest, once I get frustrated enough with Number(insert.insertId)

I also found it interesting that only AUTO_INCREMENT is supported. Not sure if that is the same behaviour as the other drivers or not