get last inserted id with mysql

noob question, but what is the preffered way to get the last inserted id using mysql? const data = await db.insert(brand).values(brandInsert) const lastId = ?? thanks?
2 Replies
Angelelz
Angelelz13mo ago
You can console.log(data) I belive it's insertedId
CharlesCharlieCharles
thanks, I didn't spot it because thought it would be directly on the data object and it didn't show up on the types autocomplete. For anybody else looking for mySQl it's
data[0].insertId
data[0].insertId
Want results from more Discord servers?
Add your server