在JOOQ中是否有一种查询ltrees的方法?

huangapple go评论64阅读模式
英文:

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

    • PreparedStatement
    • SQLOutput(可选,当您的类型包含在 UDT 中时,目前仅适用于 Oracle)
  • 从 JDBC 中读取

    • ResultSet
    • CallableStatement(可选,当您从函数的 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 ?::ltree in your case)

  • bind your data type to JDBC

    • PreparedStatement
    • SQLOutput (optional, when your type is contained in a UDT, currently only in Oracle)
  • read it from JDBC

    • ResultSet
    • CallableStatement (optional, when you fetch it from a function OUT parameter)
    • SQLInput (optional, when your type is contained in a UDT, currently only in Oracle)

huangapple
  • 本文由 发表于 2020年9月15日 14:50:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63896552.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定