Description
Describe the feature
Currently the SQL types-Java Object mappings are defined in the client and the row value buffer is decoded as fixed types does not provide an entry point for customizing the mapping.
- Postgres: https://github.com/eclipse-vertx/vertx-sql-client/blob/master/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/DataType.java
- MySQL: https://github.com/eclipse-vertx/vertx-sql-client/blob/master/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/datatype/DataType.java
- SQL Server: https://github.com/eclipse-vertx/vertx-sql-client/blob/master/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/MSSQLDataTypeCodec.java
- DB2: https://github.com/eclipse-vertx/vertx-sql-client/blob/master/vertx-db2-client/src/main/java/io/vertx/db2client/impl/drda/ClientTypes.java
We can provide an SPI for customizing the codec mapping so that users flexibly decode the row value as what they want. Since we use Netty ByteBuf
internally we can expose it to the users to use which will get maximum performance without copying the direct buffer to heap.
related feature request collections:
- Allow set/get json column as Buffer (utf-8 encoded string) #862
- Custom PostgreSQL type mapping #343
- Is there any way to disable json decoding on json/jsonb fields? #476
Use cases
-
Case1: The
BYTE
ORBIT(1)
can be decoded asBOOLEAN
, this is useful when you regard the byte types asBOOLEAN
and don't care about the exact value. -
Case2: Custom JSON mapping, the JSON row value buffer can be decoded as a custom JSON library type without unnecessary transformation
-
Case3: direct buffer usage, the row value buffer can be used directly without repeatly decoding and encoding, it's useful for a database proxy
-
Case4: support for postgres plugin data types such as hstore, the type oid is not a fixed value and therefore we need the ability to dynamically change the oid-codec mapping to correctly encode/decode the type values.
Problems
-
the ways of decoding might vary in different protocols, as sometimes the meta column information of the value is returned in another buffer and we might need to use it to decode the row value.(such as MySQL unsigned flag)
-
encoding values in some clients use a way of infering value class mechanism(i.e. the param type is inferred from the param value), we need to take care of it after we support dynamic codecs.