为什么 jooq 不允许在 whenNotMatchedInsert 中记录?
Why doesn't jooq allow a Record in whenNotMatchedInsert?
在合并查询中,我总能做到:
public <R> void insertOrUpdateRecord(TableRecord<R> record, Condition match, Map<? extends Field<?>, ?> updates) {
ctx.mergeInto(record.getTable()).using(ctx.selectOne())
.on(match)
.whenMatchedThenUpdate()
.set(updates)
.whenNotMatchedThenInsert(record.fields())
.values(toArray(record));
}
此处 toArray
转换 TableRecord
-> Object[]
的顺序与 record.fields()
中返回的相应字段相同。
所以,有什么原因我不能直接这样做:
whenNotMatchedThenInsert(record)
既然如此,目的就是插入一条新记录?
所需的功能已经可用,语法略有不同:
.whenNotMatchedThenInsert()
.set(record);
这将考虑参数记录中的所有值,Record.changed(Field)
标志是 true
在合并查询中,我总能做到:
public <R> void insertOrUpdateRecord(TableRecord<R> record, Condition match, Map<? extends Field<?>, ?> updates) {
ctx.mergeInto(record.getTable()).using(ctx.selectOne())
.on(match)
.whenMatchedThenUpdate()
.set(updates)
.whenNotMatchedThenInsert(record.fields())
.values(toArray(record));
}
此处 toArray
转换 TableRecord
-> Object[]
的顺序与 record.fields()
中返回的相应字段相同。
所以,有什么原因我不能直接这样做:
whenNotMatchedThenInsert(record)
既然如此,目的就是插入一条新记录?
所需的功能已经可用,语法略有不同:
.whenNotMatchedThenInsert()
.set(record);
这将考虑参数记录中的所有值,Record.changed(Field)
标志是 true