SqliteCustomConvertersBuilder

DSL builder collected by Sqlite.withCustomConverters. Register converters via forType (matches by declared SQL type name) or forColumn (matches by column name; takes precedence over forType).

Two overloads are available for each column or type converter:

  • Converter form — forType<T, R>(name) { raw -> ... } / forColumn<T, R>(name) { raw -> ... }. Accepts a lambda that converts each raw stored value; the column's type is derived from the reified R via typeOf<R>().

  • Identity form — forType<T>(name) / forColumn<T>(name). Same shape but with no conversion — values pass through as T. Handy when SQLite's type affinity misclassifies a declared type and the built-in mapping picks the wrong Kotlin type.

Example

val format = LocalDateTime.Format {
year(); char('-'); monthNumber(); char('-'); day()
char(' ')
hour(); char(':'); minute(); char(':'); second()
chars(" UTC")
}

val sqlite = Sqlite.withCustomConverters {
// Parse a custom text representation into Instant.
forType("MY_DATETIME") { raw: String? ->
raw?.let { LocalDateTime.parse(it, format).toInstant(TimeZone.UTC) }
}

// Explicitly treat values columns with of `LONGVARCHAR` type as nullable strings.
// This is necessary because SQLite type affinity assigns those columns the `NUMERIC`
// base type, causing DataFrame to expect integer values.
// No conversion is performed; only the expected value type is specified.
forType<String?>("LONGVARCHAR")

// Override conversion for a specific "time" column.
// Column-specific converters take precedence over type-specific converters.
forColumn("time") { raw: String -> raw.toDouble() }
}

val df = DataFrame.readSqlTable(connection, "events", dbType = sqlite)

Constructors

Link copied to clipboard
internal constructor()

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
inline fun <reified T> forColumn(columnName: String)

Register an identity converter for a specific column by name: values pass through unchanged, but the DataFrame column type is fixed to T (resolved via typeOf<T>()). Column-name overrides take precedence over type-name overrides.

inline fun <reified T, reified R> forColumn(columnName: String, crossinline convert: (T) -> R)

Register a converter for a specific column by name. Column-name overrides take precedence over type-name overrides registered via forType.

Link copied to clipboard
inline fun <reified T> forType(sqlTypeName: String)

Register an identity converter for every column with the given declared SQL type name: values pass through unchanged, but the DataFrame column type is fixed to T (resolved via typeOf<T>()).

inline fun <reified T, reified R> forType(sqlTypeName: String, crossinline convert: (T) -> R)

Register a converter for every column with the given declared SQL type name.