[FEATURE]: Return insert id as the result of insert statement
Describe what you want
For almost all of my project I used MySQL database and autoincrement ids. After executing an insert statement, I expect to get an id of the thing I just have inserted. But it is not the case with drizzle orm, since MySQL does not support returning statement. That means that here is no convenient way to freshly generated id of a row I just inserted.
But it doesn't have to be that way. Both mysql2 and @planetscale/database support returning insert id from insert statement, and I am pretty sure it is also possible in http proxy. As for now, drizzle lacks functionality to return insert id. I suggest adding a new method to drizzle's query builder called .returnInsertId(). The method should return a single value or a list of values depending on how many rows have been inserted.
const [res] = await this.drizzle.insert(schema).values({
data: value
})
res.insertId // is this what you are looking for?
Thank you! That is exactly what I was looking for.
Before posting this issue, I read the hole docs on insert statement and could not find anything useful. I'll make a PR to update the docs soon.