英文:
Is there a way to query ltrees in JOOQ?
问题
有没有什么扩展可以让我在 JOOQ 中使用 Postgres 的 ltrees,而不必使用原始 SQL?
也许有办法自己制作一个吗?
英文:
Is there any sort of extension that would allow me to use Postgres ltrees in JOOQ without having to use raw SQL?
Any way to make one myself maybe?
答案1
得分: 2
从 jOOQ 3.17 开始:
通过 #13188,jOOQ 已经通过 jooq-postgres-extensions 模块为 LTREE 类型(以及类似类型)添加了本地支持:
<dependency>
  <groupId>org.jooq</groupId>
  <artifactId>jooq-postgres-extensions</artifactId>
</dependency>
只需将该模块添加到代码生成和运行时类路径中,代码生成器将自动为您配置相关的 Binding。
在 jOOQ 3.17 之前:
您需要实现一个自定义数据类型绑定(org.jooq.Binding),并将其应用于您生成的代码:https://www.jooq.org/doc/latest/manual/code-generation/custom-data-type-bindings。
Binding 允许您告诉 jOOQ 如何:
- 
为其生成 SQL(在您的情况下可能类似于
?::ltree) - 
将您的数据类型绑定到 JDBC
PreparedStatementSQLOutput(可选,当您的类型包含在 UDT 中时,目前仅适用于 Oracle)
 - 
从 JDBC 中读取
ResultSetCallableStatement(可选,当您从函数的OUT参数中获取它时)SQLInput(可选,当您的类型包含在 UDT 中时,目前仅适用于 Oracle)
 
英文:
Starting from jOOQ 3.17:
With #13188, jOOQ has added native support for LTREE types (and similar) via the jooq-postgres-extensions module:
<dependency>
  <groupId>org.jooq</groupId>
  <artifactId>jooq-postgres-extensions</artifactId>
</dependency>
Just add that module to both code generation and runtime classpaths, and the code generator will auto-configure the relevant Binding for you.
Before jOOQ 3.17:
You have to implement a custom data type binding (org.jooq.Binding) and apply that to your generated code: https://www.jooq.org/doc/latest/manual/code-generation/custom-data-type-bindings.
A Binding allows you to tell jOOQ how to:
- 
generate SQL for it (probably something like
?::ltreein your case) - 
bind your data type to JDBC
PreparedStatementSQLOutput(optional, when your type is contained in a UDT, currently only in Oracle)
 - 
read it from JDBC
ResultSetCallableStatement(optional, when you fetch it from a functionOUTparameter)SQLInput(optional, when your type is contained in a UDT, currently only in Oracle)
 
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论