ColumnInfo

@Target([AnnotationTarget.FIELD, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER]) class ColumnInfo
androidx.room.ColumnInfo

Allows specific customization about the column associated with this field.

For example, you can specify a column name for the field or change the column's type affinity.

Summary

Nested classes

The SQLite column type constants that can be used in typeAffinity()

Constants

static Int

Collation sequence for case-sensitive match.

static Int

Column affinity constant for binary data.

static String

Constant to let Room inherit the field name as the column name.

static Int

Column affinity constant for integers or booleans.

static Int

Collation sequence that uses system's current locale.

static Int

Collation sequence for case-insensitive match.

static Int

Column affinity constant for floats or doubles.

static Int

Collation sequence for case-sensitive match except that trailing space characters are ignored.

static Int

Column affinity constant for strings.

static Int

Undefined type affinity.

static Int

Collation sequence that uses Unicode Collation Algorithm.

static Int

Collation sequence is not specified.

Public constructors

<init>(name: String, typeAffinity: Int, index: Boolean, collate: Int)

Allows specific customization about the column associated with this field.

Properties

Int

The collation sequence for the column, which will be used when constructing the database.

Boolean

Convenience method to index the field.

String

Name of the column in the database.

Int

The type affinity for the column, which will be used when constructing the database.

Constants

BINARY

static val BINARY: Int

Collation sequence for case-sensitive match.

Value: 2

See Also

BLOB

static val BLOB: Int

Column affinity constant for binary data.

Value: 5

See Also

INHERIT_FIELD_NAME

static val INHERIT_FIELD_NAME: String

Constant to let Room inherit the field name as the column name. If used, Room will use the field name as the column name.

Value: "[field-name]"

INTEGER

static val INTEGER: Int

Column affinity constant for integers or booleans.

Value: 3

See Also

LOCALIZED

static val LOCALIZED: Int

Collation sequence that uses system's current locale.

Value: 5

See Also

NOCASE

static val NOCASE: Int

Collation sequence for case-insensitive match.

Value: 3

See Also

REAL

static val REAL: Int

Column affinity constant for floats or doubles.

Value: 4

See Also

RTRIM

static val RTRIM: Int

Collation sequence for case-sensitive match except that trailing space characters are ignored.

Value: 4

See Also

TEXT

static val TEXT: Int

Column affinity constant for strings.

Value: 2

See Also

UNDEFINED

static val UNDEFINED: Int

Undefined type affinity. Will be resolved based on the type.

Value: 1

See Also

UNICODE

static val UNICODE: Int

Collation sequence that uses Unicode Collation Algorithm.

Value: 6

See Also

UNSPECIFIED

static val UNSPECIFIED: Int

Collation sequence is not specified. The match will behave like BINARY.

Value: 1

See Also

Public constructors

<init>

ColumnInfo(name: String, typeAffinity: Int, index: Boolean, collate: Int)

Allows specific customization about the column associated with this field.

For example, you can specify a column name for the field or change the column's type affinity.

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.

Return
Int: The collation sequence of the column. This is either UNSPECIFIED, BINARY, NOCASE, RTRIM, LOCALIZED or UNICODE.

index

val index: Boolean

Convenience method to index the field.

If you would like to create a composite index instead, see: Index.

Return
Boolean: True if this field should be indexed, false otherwise. Defaults to false.

name

val name: String

Name of the column in the database. Defaults to the field name if not set.

Return
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 field's type and available TypeConverters.

See SQLite types documentation for details.

Return
Int: The type affinity of the column. This is either UNDEFINED, TEXT, INTEGER, REAL, or BLOB.