[英]jOOQ select field datatype
Is it possible in jOOQ to change field datatype when doing select? 在进行选择时,jOOQ是否可以更改字段数据类型?
For example I have jOOQ generated sources and there is field X and I want to change it's data type. 例如,我有jOOQ生成的源,并且有字段X,我想更改它的数据类型。 I'm trying to add converter.
我正在尝试添加转换器。
Example: 例:
select(PERSON.field(PERSON.ADDRESS.getName(), addressConverter.getDataType()));
I can't replace table field easily. 我无法轻松替换表格字段。 I need to remove field from table fields and then make new select (example).
我需要从表字段中删除字段,然后进行新选择(示例)。
The simplest way to "change" a field to have a new data type for a specific SELECT
query is to use Field.coerce(DataType)
. 对于特定的
SELECT
查询,将字段“更改”为具有新数据类型的最简单方法是使用Field.coerce(DataType)
。 For example: 例如:
select(PERSON.ADDRESS.coerce(addressConverter.getDataType()))
.from(...)
If you want to retain all the other fields in the PERSON
table, you could proceed like this: 如果要保留
PERSON
表中的所有其他字段,可以这样进行:
select(Stream.of(PERSON.fields()).map(
f -> f == PERSON.ADDRESS
? f.coerce(addressConverter.getDataType())
: f).toArray(Field[]::new))
.from(...)
Of course, you could also factor out this particular data type replacement in a dedicated function. 当然,您也可以在专用功能中排除此特定数据类型的替换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.