是否可以选择记录的所有值,而不必分别选择每个值? [英] Is it possible to select all values of a record instead of having to select each value separately?

查看:56
本文介绍了是否可以选择记录的所有值,而不必分别选择每个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要选择一条记录的所有值. 我了解到可以使用DSL.val()函数分别选择记录的每个值. 假设我们有一个具有以下属性的记录R: name: Stringnumber: Int.分别选择记录的每个值将看起来像这样:

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

您可以猜测,当您拥有15个属性的记录时,这将变得非常乏味.

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

是否可以选择一条记录的所有值,而不必分别选择每个值?

我想像这样:

ctx.select(myRecord)

推荐答案

如果不需要类型安全性,则可以使用

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

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

这将产生一个Select<Record>,其列数对于编译器是未知的.如果您希望从特定的R记录类型提供的附加类型安全中获利(我假设例如Record2<String, Integer>),则可以使用

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

这篇关于是否可以选择记录的所有值,而不必分别选择每个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆