question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce SPI Row/Tuple converter

See original GitHub issue

Describe 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 type
  • ColumnConverter 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:open
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vietjcommented, Aug 5, 2021

as for Interval we should I think add a method to convert to Duration

0reactions
zero88commented, Aug 5, 2021

how about doing that directly on the Query`` with the map method ? you would provide a Function<Row, Row> that performs the desired mapping instead

Ya, I think it can be good to add it as ad-hoc query. However, Row is “lenient immutable” that unable to set 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 about UDT, something like I have Address UDT in database, then I want to map it as Pojo class directly to Address.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 be interface instead of Enum
  • DataTypeCodec is able to override instead of static
Read more comments on GitHub >

github_iconTop Results From Across the Web

Serial Peripheral Interface (SPI) - SparkFun Learn
Introduction. Serial Peripheral Interface (SPI) is an interface bus commonly used to send data between microcontrollers and small peripherals such as shift ...
Read more >
Introduction to SPI Interface - Analog Devices
Multi-subnode switches using a serial-to-parallel converter. An alternative method is to use SPI controlled switches. This method provides the benefit of ...
Read more >
SPI - Introduction to Serial Peripheral Interface - Seeed Studio
SPI is one of the most popular communication peripheral used by microcontrollers (eg. ... analog-to-digital converters, and many more.
Read more >
AN-1065 SPI Serial to Parallel Converter | Renesas
This serial signal can be converted to parallel information by the SLG46620 IC. Please note that the maximum number of bits which can...
Read more >
Basics of the SPI Communication Protocol - Circuit Basics
The simplest configuration of SPI is a single master, single slave system, but one master can control more than one slave (more on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found