Introduce SPI Row/Tuple converter
See original GitHub issueDescribe the feature
Add new convention method for Row
to accept converter
.
Introduce 2 converter interfaces, it should be 2-way converter: JDBC
/Reactive SQL
<=> User data type.
DataTypeConverter
for converting by data typeColumnConverter
for converting by data type and column name
Something like that
interface Row {
default <T> T get(String column, ColumnConverter<T> converter) {
return converter.convert(getValue(column));
}
}
Then extract every get<Type>
to Converter
, then add them to SPI
as Vertx convention.
On each database driver/business model, developer can easy enhance or override default converter and make seamlessly UDT from database to java type
The concept will be similar on what I have done in jooqx such as: https://github.com/zero88/jooqx/blob/fcc473908cdbcc7b61544ccfbc97b4f7a8797b13/core/src/main/java/io/zero88/jooqx/datatype/JooqxConverter.java#L19 and https://github.com/zero88/jooqx/blob/fcc473908cdbcc7b61544ccfbc97b4f7a8797b13/core/src/main/java/io/zero88/jooqx/datatype/DataTypeMapperRegistry.java#L23
Contribute
I might take it if you want to minimum API change in my lib also.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
as for
Interval
we should I think add a method to convert toDuration
Ya, I think it can be good to add it as ad-hoc query. However,
Row
is “lenient immutable” that unable toset value at index
in public API, and no public constructor (I think should not coz duplicate memory when copy).Interval
is one of example. I have more consider aboutUDT
, something like I haveAddress UDT
in database, then I want to map it as Pojo class directly toAddress.java
I thought a inject converter can start from here (PostgreSQL example but similar to others):
https://github.com/eclipse-vertx/vertx-sql-client/blob/35188239370f3ad3d19b18a0b1b43e54d160d2a7/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/RowResultDecoder.java#L43-L48
DataType
can beinterface
instead ofEnum
DataTypeCodec
is able to override instead of static