mysql InsertResult always empty
my app is heavy id/transaction user and i need the id of created register to insert another register but InsertResult always is empty
12 Replies
now i doing an workaround like this
What do you mean by empty? The result object doesn't have the
insertId
property? If you're just console.log
ging the result, it always seems like an empty object. The properties are non-enumerable getters.
If the insertId
is still empty when you do this
please provide more information:
* Kysely version
* Which dialect are you using
* The exact code you're trying to run
* How it fails
* What are you expecting to happen
* Any errors you see* Kysely version
- "kysely": "^0.23.5"
* Which dialect are you using
- i tried PlanetScaleDialect and MysqlDialect, same result in both
* The exact code you're trying to run
* How it fails
- the received return from console.log is
[ InsertResult {} ]
* What are you expecting to happen
- return id of insert
* Any errors you see
- no errorsHey 👋
* How it fails - the received return from console.log is [ InsertResult {} ]You're trying to print a class instance with non-enumerable getters. Try printing
result.insertId
instead.@Igal We should probably make the properties enumerable somehow. This is not the first time this has been reported.
In general, this type of stuff is why I prefer using uuids/cuid2 nowadays.
I think we can call
Object.defineProperty(InsertResult.prototype, 'insertId', {enumerable: true})
Didn't know defineProperty
can be used for an existing propertyYeah its a thing, I used to do it with Error.message
worked, thanks
Does this not cause performance issues?
transactions are arguably worse for performance.
any locking in write-heavy workflows is bad
I agree with you
i exaggerated a bit when I said that my app was transaction heavy user haha
you could generate a guid, pass the entity to a queue+dlq.. and then deal with the writing in parallel without a transaction and without fear of data loss. reads would still use inner joins and would filter out things that were not written to both tables yet