You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
generatedKey is a bad api. It returns a number for an implicit column. This is bad as it effectively forces one to duplicate the column type (ie. doing a generatedKey as Int or generatedKey!!.toInt()) and which column is autoincrement at each usage (ie. you probably need to use the number in another query where you then embed the assumption of which column the generated key came from).
There is already a better way which is the InsertStatement.get(column) which preserves the type and makes it explicit at each usage which column the value was expected to appear from.
There was a brief talk about this on slack, but I create an issue here for added visibility:
Johannes Jensen [Yesterday at 11:35 AM]
Looking at `InsertStatement.generatedKey`. Is there any particular usecase that isnt better handled by `get()` ?
With `get()` you get the correct type, while with `generatedKey` you need to `toInt()` it or similar. Asking as I would prefer to see it removed since I see some bad usages of it in our codebase. (edited)
2 replies
Andrey Tarashevskiy [21 hours ago]
I think that it's rather rare when you have to ask `generatedKey` in your code.
At first, if you use `IdTable.insertAndGetId` then you'll receive id value of proper type.
So I agree that `generatedKey` looks like a legacy and could be hidden from a public scope. But (as you mentioned) many people already use that field and it may be too painful to just to remove the field but we can start with depreciation.
Johannes Jensen [21 hours ago]
Good to hear you agree. Deprecation seems like a good first step.
The text was updated successfully, but these errors were encountered:
Will BatchInsertStatement.generatedKey still accessible? generatedKey seems the only way to get multiple generated results from batch statement, due to InsertStatement.resultedValues is protected.
@xJoeWoo, I plan to replace generateKey with some kind of result: List<ResultRow>, then it will be able to write: result.get(idCol) to obtain key in upsert sample.
generatedKey
is a bad api. It returns a number for an implicit column. This is bad as it effectively forces one to duplicate the column type (ie. doing ageneratedKey as Int
orgeneratedKey!!.toInt()
) and which column is autoincrement at each usage (ie. you probably need to use the number in another query where you then embed the assumption of which column the generated key came from).There is already a better way which is the
InsertStatement.get(column)
which preserves the type and makes it explicit at each usage which column the value was expected to appear from.There was a brief talk about this on slack, but I create an issue here for added visibility:
The text was updated successfully, but these errors were encountered: