合成默认值
适用于 ❌ 开源版 ✅ Express 版 ✅ 专业版 ✅ 企业版
如果数据库报告列具有默认表达式,jOOQ 的代码生成器可以识别这些表达式。某些数据库不支持“真正的”默认列,或者不将列默认值从底层表传播到视图。如果列是已知的“默认”列,但形式上不是,则用户可以指定匹配所有表和列的正则表达式,并为这些表和列提供默认表达式。例如
XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration> <generator> <database> <syntheticObjects> <defaults> <default> <!-- Optional regular expression matching all tables that have this identity. --> <tables>SCHEMA\.TABLE</tables> <!-- List all columns that are identities --> <fields>CREATION_DATE</fields> <!-- A valid SQL expression to apply as a default (e.g. 'string value', not string value) --> <expression>CURRENT_TIMESTAMP</expression> </default> </defaults> </syntheticObjects> </database> </generator> </configuration>
有关更多详细信息,请参阅 配置 XSD、独立代码生成和 maven 代码生成。
new org.jooq.meta.jaxb.Configuration() .withGenerator(new Generator() .withDatabase(new Database() .withSyntheticObjects(new SyntheticObjectsType() .withDefaults( new SyntheticDefaultType() // Optional regular expression matching all tables that have this identity. .withTables("SCHEMA\\.TABLE") // List all columns that are identities .withFields("CREATION_DATE") // A valid SQL expression to apply as a default (e.g. 'string value', not string value) .withExpression("CURRENT_TIMESTAMP") ) ) ) )
import org.jooq.meta.jaxb.* configuration { generator { database { syntheticObjects { defaults { default_ { // Optional regular expression matching all tables that have this identity. tables = "SCHEMA\\.TABLE" // List all columns that are identities fields = "CREATION_DATE" // A valid SQL expression to apply as a default (e.g. 'string value', not string value) expression = "CURRENT_TIMESTAMP" } } } } } }
有关更多详细信息,请参阅 配置 XSD 和 gradle 代码生成。
configuration { generator { database { syntheticObjects { defaults { default_ { // Optional regular expression matching all tables that have this identity. tables = "SCHEMA\\.TABLE" // List all columns that are identities fields = "CREATION_DATE" // A valid SQL expression to apply as a default (e.g. 'string value', not string value) expression = "CURRENT_TIMESTAMP" } } } } } }
有关更多详细信息,请参阅 配置 XSD 和 gradle 代码生成。
// The jOOQ-codegen-gradle plugin has been introduced in version 3.19. // Please use the official plugin instead of the third party plugin that was recommended before.
一如既往,当使用正则表达式时,它们是具有默认标志的正则表达式。
反馈
您对此页面有任何反馈吗? 我们很乐意听到您的反馈!