android,将 Room 与 kotlin 结合使用,如何在字段上添加唯一约束
android, using Room with kotlin, how to add unique constrain on a field
per Annotate indices and uniqueness,似乎可以像下面那样添加唯一约束,
但在 AndroidStudio 3 中出现错误(编辑器有红色下划线表示 "unresolved the reference:indices"),:
/Users/application/database/DbAuthor.kt
Error:(14, 39) Expecting an element
@Entity(tableName = "author" indices = arrayOf(Index(value = "authorid", unique = true)))
class DbAuthor(
@ColumnInfo(name = "authorid")
var authorid: Int? = null,
如何在使用 kotlin 时在字段上添加唯一约束?
gradle 就像:
buildscript {
ext {
verAndroidSupport = '27.0.0'
arch = "1.0.0"
archRoomVersion = "1.0.0"
}
ext.kotlin_version = '1.2.20'
和
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
//arch
implementation "android.arch.lifecycle:runtime:${arch}"
implementation "android.arch.lifecycle:extensions:${arch}"
annotationProcessor "android.arch.lifecycle:compiler:${arch}"
//room
compile "android.arch.persistence.room:runtime:${archRoomVersion}"
annotationProcessor "android.arch.lifecycle:compiler:${arch}"
annotationProcessor "android.arch.persistence.room:compiler:${archRoomVersion}"
kapt "android.arch.persistence.room:compiler:1.0.0-alpha1"
您在 "author"
之后错过了 ,
@Entity(tableName = "author", indices = arrayOf(Index(value = "authorid", unique = true)))
per Annotate indices and uniqueness,似乎可以像下面那样添加唯一约束,
但在 AndroidStudio 3 中出现错误(编辑器有红色下划线表示 "unresolved the reference:indices"),:
/Users/application/database/DbAuthor.kt
Error:(14, 39) Expecting an element
@Entity(tableName = "author" indices = arrayOf(Index(value = "authorid", unique = true)))
class DbAuthor(
@ColumnInfo(name = "authorid")
var authorid: Int? = null,
如何在使用 kotlin 时在字段上添加唯一约束?
gradle 就像:
buildscript {
ext {
verAndroidSupport = '27.0.0'
arch = "1.0.0"
archRoomVersion = "1.0.0"
}
ext.kotlin_version = '1.2.20'
和
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
//arch
implementation "android.arch.lifecycle:runtime:${arch}"
implementation "android.arch.lifecycle:extensions:${arch}"
annotationProcessor "android.arch.lifecycle:compiler:${arch}"
//room
compile "android.arch.persistence.room:runtime:${archRoomVersion}"
annotationProcessor "android.arch.lifecycle:compiler:${arch}"
annotationProcessor "android.arch.persistence.room:compiler:${archRoomVersion}"
kapt "android.arch.persistence.room:compiler:1.0.0-alpha1"
您在 "author"
之后错过了 ,
@Entity(tableName = "author", indices = arrayOf(Index(value = "authorid", unique = true)))