DT
Drizzle Team•2y ago
b0o

Why is insertId a string, not a number?

After inserting into a table with an auto-incrementing pk, the insertId in the returned ExecutedQuery is a string. Why isn't it a number?
8 Replies
AlcaponeYou
AlcaponeYou•2y ago
can you post the schema of the table, and the ts code too. I've made mistakes where I duplicated the table column name which overrides the pk.
b0o
b0oOP•2y ago
Actually, I think this has nothing to do with drizzle, it seems it's coming from PlanetScale's database.js: https://github.com/planetscale/database-js/blob/8b1a360abd9b7b28ab953984e2aa9bd242d8a169/src/index.ts#L27
GitHub
database-js/src/index.ts at 8b1a360abd9b7b28ab953984e2aa9bd242d8a16...
A Fetch API-compatible PlanetScale database driver - database-js/src/index.ts at 8b1a360abd9b7b28ab953984e2aa9bd242d8a169 · planetscale/database-js
b0o
b0oOP•2y ago
export interface ExecutedQuery {
headers: string[]
types: Types
rows: Row[]
fields: Field[]
size: number
statement: string
insertId: string
rowsAffected: number
time: number
}
export interface ExecutedQuery {
headers: string[]
types: Types
rows: Row[]
fields: Field[]
size: number
statement: string
insertId: string
rowsAffected: number
time: number
}
AlcaponeYou
AlcaponeYou•2y ago
oh you're trying to get the inserted data. I forgot mysql doesn't have returning. I wonder if drizzle has .returning() for mysql. I'm using sqlite and I'm able to do returnining().get() to retrieve the new inserted data
b0o
b0oOP•2y ago
It doesn't have returning 😦 I wish it did
b0o
b0oOP•2y ago
GitHub
Insert, update and delete with return for MySQL · drizzle-team driz...
V0.26 introduced a lot of very nice features! One very interesting is relational queries and insert, update and delete with return. Is there a plan to add MySQL to the list? Or is there any technic...
b0o
b0oOP•2y ago
This was answered in tweet: MySQL does not provide returning and you always have to make an extra select and we don't do anything implicitly. That's a little less DX, but in a long run it's a win for everybody
Andrii Sherman
Andrii Sherman•2y ago
Yes, for insertId we just proxy driver behavior and also as long as MySQL doesn't have .returning we won't have it in Core API. But may have in some sort of helpers api on top of Core
Want results from more Discord servers?
Add your server