r2dbc / r2dbc-spi

Service Provider Interface for R2DBC Implementations
Apache License 2.0
421 stars 57 forks source link

Change default mapping of BLOB and CLOB column types to ByteBuffer and String #130

Closed gm2552 closed 5 years ago

gm2552 commented 5 years ago

Related to r2dbc-h2 issue https://github.com/r2dbc/r2dbc-h2/issues/115. It is desirable that data field columns of type BLOB and CLOB map to ByteBuffer and byte[] data types in entity objects.

mp911de commented 5 years ago

That would be BLOB maps to either ByteBuffer or byte[] and String for CLOB. Our decision that LOB columns return io.r2dbc.spi.Blob/Clob by default was probably premature optimization.

For easier consumption in libraries that apply object mapping, it probably makes sense to introduce scalar value mapping and use scalar values instead of LOB wrappers by default. JDBC behaves in a similar way, BYTEA (Postgres), VARBINARY(MAX) (SQL Server), and BLOB (MySQL) return byte arrays when calling ResultSet.getObject(…).

Thoughts? /cc @davecramer @odrotbohm @nebhale @gregturn

davecramer commented 5 years ago

In the case of PostgreSQL at least it makes sense to map BYTEA to byte[]

mp911de commented 5 years ago

/cc @mirromutth

mirromutth commented 5 years ago

For now, the default type mapping in r2dbc-mysql is BLOB/TEXT to LOB types and VARBINARY/VARCHAR/CHAR to scalar types.

Yes, I saw mysql-connector-j which prefer to convert BLOB to byte[], so I vote to use scalar types for default type mappings.