How can I get multi-line queries to be injected? It works on Room with Java classes, but does Kotlin support this as well?

E.g. I have 2 queries here, and only the top SQL query (1 line) gets injected.

I tried to follow the steps in this guide but could not find the required settings.

There is an issue at https://youtrack.jetbrains.com/issue/KT-13636 which suggests this is fixed, but I'm not sure how to implement the fix.

推荐答案

You can use a raw string which is more readable anyway:

@Dao
interface ItemDao {
    @Query("""
        SELECT * FROM Item
        WHERE Item.id = :id
        """)
    fun loadItemById(id: Long): LiveData<Item>
}

Kotlin相关问答推荐

Kotlin -通过反射获得KProperty 1和CallableReference的实例

T和T有什么区别:任何>

如何在Docker中使用Selenium和chromedriver?

使函数同时挂起和取消挂起

Kotlin .如何用从 1 到 90 的 5 个唯一数字填充列表中的每一行?

Kotlin:使用另一个列表和字母顺序对列表进行排序的有效方法

在子类中覆盖 kotlin 运算符扩展函数

通用接口继承

将 SharedPreferences 中的值公开为流

有没有一种简单的方法可以将数组/列表中的每个元素相互相乘 - Kotlin?

如何为 Kotlin 中的每个循环设置以避免越界异常

如何判断给定字符串是否多次包含另一个子字符串?

匹配在单词边界上包含特殊字符的变量字符串的正则表达式

从字符串列表构建字符串

无法创建类 ViewModel kotlin 的实例

将 Android Studio 升级到 3.1.0 后的 Android Support 插件错误

如何将命令行参数传递给Gradle Kotlin DSL

使用导航组件在BottomNavigationView中传递参数

保存对象时未填充 Spring Boot JPA@CreatedDate @LastModifiedDate

从另一个列表创建一个列表