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
In the function createPerson since mood is nullable, we need to do mood?.value instead of mood.value. Kotlin will fail to compile.
Runtime Nullpointer
When calling listPeople(..), a nullpointer exception will be thrown. This is because
results.getString(3) is returning null and Mood.lookup(..) does not allow the argument to be nullable. The function signature is lookup(value: String)
If the lookup(..) function is updated to accept nullable, it will still throw an error because of the !! on Mood.lookup(results.getString(3))!! since null will be returned from lookup(..)
Proposed changes
If the enum is nullable, ensure we use ?. to get the value
Update the generated lookup(..) to accept nullable, if the column is nullable
If the column is nullable, do not add the !! when selecting the column
I have manually updated the generated code to do the above and things work for me.
The text was updated successfully, but these errors were encountered:
Environment
postgresql
sqlc-gen-kotlin_1.2.0.wasm
/22b437ecaea66417bbd3b958339d9868ba89368ce542c936c37305acf373104b
Issue
Setup
I have the following migration.
I have the following queries.
Generated Code
The generated models
Generated queries
Errors
Compile Error
In the function
createPerson
sincemood
is nullable, we need to domood?.value
instead ofmood.value
. Kotlin will fail to compile.Runtime Nullpointer
When calling
listPeople(..)
, a nullpointer exception will be thrown. This is becauseresults.getString(3)
is returning null andMood.lookup(..)
does not allow the argument to be nullable. The function signature islookup(value: String)
lookup(..)
function is updated to accept nullable, it will still throw an error because of the!!
onMood.lookup(results.getString(3))!!
since null will be returned fromlookup(..)
Proposed changes
?.
to get the valuelookup(..)
to accept nullable, if the column is nullable!!
when selecting the columnI have manually updated the generated code to do the above and things work for me.
The text was updated successfully, but these errors were encountered: