https://kotlinlang.org logo
#exposed
Title
# exposed
m

Mathias Rørvik

11/23/2020, 2:21 PM
What is the best practice, when It comes to returning a result from a query?
Copy code
fun getSymbolId(symbol: String): Int {
    transaction {
        Symbols.select { Symbols.symbol eq symbol }.toList().first()
    }
}
j

Joel

11/23/2020, 9:12 PM
Symbols.select { Symbols.symbol eq symbol }.first()
will be more efficient.
.toList()
will pull all results into memory, whereas
.first()
will limit 1.
m

Mathias Rørvik

11/24/2020, 7:38 PM
I see, but it wasn't really what I was asking. What's the best practice when it comes to returning the actual result of the select?
nvm, I figured it out 🙂