This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2885892-server-side-kotlin-with-ktor/lessons/21
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2885892-server-side-kotlin-with-ktor/lessons/21
How do you determine when to wrap inside dbQuery
and when to not wrap inside dbQuery
? E.g. suspend fun user
is a select statement wrapped in dbQuery
, but suspend fun phrase
is a select statement not wrapped in dbQuery
.
Thanks for the question @rajohns! Generally speaking, you should use dbQuery
. In my version of the code, my first phrase
function does use dbQuery
, but the second phrase
function does not since it鈥檚 just passing the call along to the first. You can see that in video 19 at about the 8 minute mark. (Note that the clear
function, which we never ended up using, probably should have used dbQuery
too.)
I hope that helps and thanks again for the question!
Hi Ray,
I鈥檝e been having a problem connecting to the database. I鈥檓 still googling it but @ the moment this is the error i鈥檓 getting. Please can you point me in the right direction.
Caused by: java.lang.RuntimeException: Failed to load driver class org.postgresql.Driver in either of HikariConfig class loader or Thread context classloader
at com.zaxxer.hikari.HikariConfig.setDriverClassName(HikariConfig.java:485)
Hi @arkangelx, thanks for the question! Are you able to connect to the emojiphrases
database using psql
from the command line, as in the earlier lesson?
Also, make sure you鈥檙e using the same versions of the libraries used in the course.
Hi Ray, apologies for late response. I found the fix to that problem. It was a misspelt package name in gradle.
Hi Joe, I am a little bit confusing in the user
function, why did you return the user
object when hash
is null?
Thanks for the question @taoobb! The logic here is that if hash
is null
, that means a hash was not passed into the function, and so we鈥檙e just querying the database based on userId
. So we return the user for that ID as a result. It might be better in a production app to separate out that logic into a separate call for clarity. Thanks again!
I鈥檓 still confused. It feels that the when block in the user function can be simply replaced by return user
@macsimus Can you please help with this when you get a chance? Thank you - much appreciated! :]