Is it possible to select all values of a record in

2019-08-04 10:54发布

I need to select all the values of a record. I learned that it´s possible to select each value of the record separately using the DSL.val() function. Let´s say we have a record R with the following properties: name: String, number: Int. Selecting each value of the record separately would look like this:

R myRecord = new R()
ctx.select(val(myRecord.name), val(myRecord.number))

As you can guess this will get pretty tedious when you have a record with 15 properties.

Is it possible to select all values of a record instead of having to select each value separately?

I imagine something like this:

ctx.select(myRecord)

1条回答
smile是对你的礼貌
2楼-- · 2019-08-04 11:24

If you don't need the type safety, then you can use Record.valuesRow().fields():

ctx.select(myRecord.valuesRow().fields());

This will produce a Select<Record>, whose number of columns is unknown to the compiler. If you prefer profiting from the additional type safety provided by your specific R record type (I'm assuming e.g. Record2<String, Integer>), then you can use the values() constructor:

ctx.selectFrom(values(myRecord.valuesRow()));
查看更多
登录 后发表回答