ColumnInfo
-
Cmn
@Target(allowedTargets = [AnnotationTarget.FIELD, AnnotationTarget.FUNCTION])
@Retention(value = AnnotationRetention.BINARY)
annotation ColumnInfo
Allows specific customization about the column associated with this property.
For example, you can specify a column name for the property or change the column's type affinity.
Summary
Nested types |
|---|
@IntDef(value = [1, 2, 3, 4, 5, 6]) |
@IntDef(value = [1, 2, 3, 4, 5])The SQLite column type constants that can be used in typeAffinity() |
Constants |
||
|---|---|---|
const Int |
BINARY = 2Collation sequence for case-sensitive match. |
Cmn
|
const Int |
BLOB = 5Column affinity constant for binary data. |
Cmn
|
const String |
Constant to let Room inherit the property name as the column name. |
Cmn
|
const Int |
INTEGER = 3Column affinity constant for integers or booleans. |
Cmn
|
const Int |
LOCALIZED = 5Collation sequence that uses system's current locale. |
Cmn
|
const Int |
NOCASE = 3Collation sequence for case-insensitive match. |
Cmn
|
const Int |
REAL = 4Column affinity constant for floats or doubles. |
Cmn
|
const Int |
RTRIM = 4Collation sequence for case-sensitive match except that trailing space characters are ignored. |
Cmn
|
const Int |
TEXT = 2Column affinity constant for strings. |
Cmn
|
const Int |
UNDEFINED = 1Undefined type affinity. |
Cmn
|
const Int |
UNICODE = 6Collation sequence that uses Unicode Collation Algorithm. |
Cmn
|
const Int |
UNSPECIFIED = 1Collation sequence is not specified. |
Cmn
|
const String |
A constant for defaultValue() that makes the column to have no default value. |
Cmn
|
Public constructors |
|
|---|---|
|
Cmn
|
Public properties |
||
|---|---|---|
Int |
The collation sequence for the column, which will be used when constructing the database. |
Cmn
|
String |
The default value for this column. |
Cmn
|
Boolean |
Convenience method to index the property. |
Cmn
|
String |
Name of the column in the database. |
Cmn
|
Int |
The type affinity for the column, which will be used when constructing the database. |
Cmn
|
Constants
INHERIT_FIELD_NAME
const val INHERIT_FIELD_NAME: String
Constant to let Room inherit the property name as the column name. If used, Room will use the property name as the column name.
INTEGER
const val INTEGER = 3: Int
Column affinity constant for integers or booleans.
| See also | |
|---|---|
typeAffinity |
() |
LOCALIZED
const val LOCALIZED = 5: Int
Collation sequence that uses system's current locale.
| See also | |
|---|---|
collate |
() |
REAL
const val REAL = 4: Int
Column affinity constant for floats or doubles.
| See also | |
|---|---|
typeAffinity |
() |
RTRIM
const val RTRIM = 4: Int
Collation sequence for case-sensitive match except that trailing space characters are ignored.
| See also | |
|---|---|
collate |
() |
UNDEFINED
const val UNDEFINED = 1: Int
Undefined type affinity. Will be resolved based on the type.
| See also | |
|---|---|
typeAffinity |
() |
UNICODE
const val UNICODE = 6: Int
Collation sequence that uses Unicode Collation Algorithm.
| See also | |
|---|---|
collate |
() |
UNSPECIFIED
const val UNSPECIFIED = 1: Int
Collation sequence is not specified. The match will behave like BINARY.
| See also | |
|---|---|
collate |
() |
VALUE_UNSPECIFIED
const val VALUE_UNSPECIFIED: String
A constant for defaultValue() that makes the column to have no default value.
Public properties
collate
val collate: Int
The collation sequence for the column, which will be used when constructing the database.
The default value is UNSPECIFIED. In that case, Room does not add any collation sequence to the column, and SQLite treats it like BINARY.
defaultValue
val defaultValue: String
The default value for this column.
@ColumnInfo(defaultValue = "No name")
public name: String
@ColumnInfo(defaultValue = "0")
public flag: Int
Note that the default value you specify here will NOT be used if you simply insert the Entity with Insert. In that case, any value assigned in Java/Kotlin will be used. Use Query with an INSERT statement and skip this column there in order to use this default value.
NULL, CURRENT_TIMESTAMP and other SQLite constant values are interpreted as such. If you want to use them as strings for some reason, surround them with single-quotes.
@ColumnInfo(defaultValue = "NULL")
public description: String?
@ColumnInfo(defaultValue = "'NULL'")
public name: String
You can also use constant expressions by surrounding them with parentheses.
@ColumnInfo(defaultValue = "('Created at' || CURRENT_TIMESTAMP)")
public notice: String
| Returns | |
|---|---|
String |
The default value for this column. |
| See also | |
|---|---|
VALUE_UNSPECIFIED |
index
val index: Boolean
Convenience method to index the property.
If you would like to create a composite index instead, see: Index.
| Returns | |
|---|---|
Boolean |
True if this property should be indexed, false otherwise. Defaults to false. |
name
val name: String
Name of the column in the database. Defaults to the property name if not set.
| Returns | |
|---|---|
String |
Name of the column in the database. |
typeAffinity
val typeAffinity: Int
The type affinity for the column, which will be used when constructing the database.
If it is not specified, the value defaults to UNDEFINED and Room resolves it based on the property's type and available TypeConverters.
See SQLite types documentation for details.