https://kotlinlang.org logo
#getting-started
Title
# getting-started
p

pawel.barszcz

11/20/2016, 9:19 PM
here is excerpt from my code with some quick find/replace to match “Messages” case
Copy code
fun findMessageBy(messageId: String): Message? {
        return MessagesTable
                .select {
                    MessagesTable.id eq messageId.id
                }
                .map { messageFrom(it) }
                .firstOrNull()
    }

    fun createMessage(author: Author, content: String): Message {

        val newId = MessagesTable
                .insert {
                    it[MessagesTable.authorEmail] = author.email
                    it[MessagesTable.content] = content
                } get MessagesTable.id

        return findMessageBy(newId)
                ?: throw RuntimeException("Database: Cannot find Message which was just created")
    }