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

匆匆过客 提交于 2019-12-24 09:13:53

问题


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:


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()));


来源:https://stackoverflow.com/questions/52538400/is-it-possible-to-select-all-values-of-a-record-instead-of-having-to-select-each

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!