Johann Pardanaud
11/11/2023, 6:03 PMPoisonedYouth
11/11/2023, 7:02 PMdave08
11/12/2023, 10:50 AMsuspend fun findByIsbn(isbn: String): Book? = dbQuery {
Books.select { Books.isbn eq isbn }
.map { it.toBook() }
.singleOrNull()
}
is pretty wasteful for checking if a record exists... usually a select 1 from ... where ... is enough, in your case you retrieve the whole book, and go through mapping code twice, just to check that it's not null...PoisonedYouth
11/12/2023, 1:02 PMdave08
11/12/2023, 1:06 PMdave08
11/12/2023, 1:08 PMValidationResult
so that the when
can look cleaner... (or have a fold(isSuccess ..., is...)
, arrow-style...). It looks just a bit too verbose for those that'll be writing a bunch of them...Johann Pardanaud
11/12/2023, 9:32 PMJohann Pardanaud
11/12/2023, 9:33 PM