collate

protected fun <T> KQLiteColumn<T>.collate(collation: Collate): KQLiteColumn<T>

Adds a COLLATE clause to this column, specifying the text comparison behavior.

This function defines the collating sequence (or collation) to be used for text-based comparisons and sorting on this column. SQLite supports different collations that determine how strings are ordered and compared, such as case sensitivity and handling of whitespace.

This is particularly useful for TEXT columns (like those created with stringColumn, textColumn, etc.) but can be applied to any column type.

Common Collations:

  • Collate.BINARY: Compares strings byte by byte.

  • Collate.NOCASE: Case-insensitive comparison.

  • Collate.RTRIM: Ignores trailing whitespace.

Example:

object Users : KQLiteTable("users") {
val id = longColumn("id").primaryKey()

// The 'username' column will be case-insensitive for comparisons and sorting.
// Queries like `WHERE username = 'admin'` will match 'Admin', 'ADMIN', etc.
val username = stringColumn("username")
.notNull()
.unique()
.collate(Collate.NOCASE)
}

Return

The same KQLiteColumn instance, now with a collation specified, to allow for further chaining.

Author

MOHAMMAD AZIM ANSARI

Parameters

collation

The collating sequence to apply (e.g., Collate.NOCASE).

See also