Why can't I use `.value("fieldName", v)` for inser...
# spring
r
Why can't I use
.value("fieldName", v)
for inserting using fluent API for R2DBC with
v
as nullable
String?
? I have to check for
null
and use
.nullValue("fieldName")
instead. And it ruins the whole purpose of the fluent API. https://docs.spring.io/spring-data/r2dbc/docs/1.0.0.M2/reference/html/#r2dbc.datbaseclient.fluent-api.insert
s
Could you please create an issue with an example at https://github.com/spring-projects/spring-data-r2dbc ?
r
Fortunately with Kotlin it's very easy to write helper extension function, which makes things right ­čÖé
Copy code
fun <T> DatabaseClient.GenericInsertSpec<T>.safeValue(field: String, value: Any?): DatabaseClient.GenericInsertSpec<T> =
    if (value == null) {
        this.nullValue(field)
    } else {
        this.value(field, value)
    }