How to annotate a default value inside a android room entity?

前端 未结 5 859
故里飘歌
故里飘歌 2020-12-09 09:22

I couldn\'t find any information how to annotate a SQL - \"DEFAULT\" value while looking into the @ColumnInfo docs for the new Android Persistence Library.

Does Room

5条回答
  •  长情又很酷
    2020-12-09 10:26

    With the release of room persistence 2.2.0, there's a new property added to @ColumnInfo annotation which can be used to specify the default value of a column. See documentation.

    @Entity(tableName = "users")
    data class User(
        @PrimaryKey val id: Long,
        @ColumnInfo(name = "user_name", defaultValue = "temp") val name: String
        @ColumnInfo(name = "last_modified", defaultValue = "CURRENT_TIMESTAMP" ) val lastModified: String
    )
    

提交回复
热议问题