toObjects

inline fun <T : Any> ResultSet.toObjects(factory: (String) -> T?): List<T>

Maps the ResultSet to a List of objects that are created using the given factory lambda.

Example of usage with kotlinx-serialization:

@Serializable
class User(
val name: String,
val surname: String,
val age: Int
)

val users: List<User> = query.execute().toObjects { json: String ->
Json.decodeFromString<User>(json)
}

Return

a List of objects of type T

Parameters

factory

lambda used for creating an object instance


inline fun <T : Any> ResultSet.toObjects(factory: (Map<String, Any?>) -> T?): List<T>

Maps the ResultSet to a List of objects that are created using the given factory lambda.

Example of usage:

class User(map: Map<String, Any?>) {
val name: String by map
val surname: String by map
val age: Int by map
}

val users: List<User> = query.execute().toObjects(::User)

Using Kotlin Map delegation for creating such instances is a great shorthand.

Return

a List of objects of type T

Parameters

factory

lambda used for creating an object instance