jOOQ select 字段数据类型

jOOQ select field datatype

在 jOOQ 中做 select 时是否可以更改字段数据类型?

例如,我有 jOOQ 生成的源并且有字段 X,我想更改它的数据类型。我正在尝试添加转换器。

示例:

select(PERSON.field(PERSON.ADDRESS.getName(), addressConverter.getDataType()));

我无法轻松替换 table 字段。我需要从 table 字段中删除字段,然后创建新的 select (示例)。

为特定 SELECT 查询 "change" 字段提供新数据类型的最简单方法是使用 Field.coerce(DataType)。例如:

select(PERSON.ADDRESS.coerce(addressConverter.getDataType()))
.from(...)

如果您想保留 PERSON table 中的所有其他字段,您可以这样进行:

select(Stream.of(PERSON.fields()).map(
     f -> f == PERSON.ADDRESS 
        ? f.coerce(addressConverter.getDataType())
        : f).toArray(Field[]::new))
.from(...)

当然,您也可以在专用函数中分解出这种特定的数据类型替换。