访问H2数据库架构 [英] Accessing H2 database schema

查看:154
本文介绍了访问H2数据库架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 jOOQ 来访问Java中的嵌入式H2数据库,以生成表类等.我目前可以执行查询例如

Im currently accessing an embedded H2 database in java using jOOQ to generate table classes etc. I can currently execute queries such as

create.select().from(TEST).fetch()

在我的代码中,返回结果等.

in my code, return results etc.

但是我无法查询信息模式.我可以使用H2控制台正常访问它,并且为给定的information_schema表创建视图可以正常工作.我的问题是我应该如何访问information_schema例如执行诸如

However I cant query the information schema. I can access it ok using the H2 console, and creating a view for a given information_schema table works fine. My question is how should I be accessing the information_schema eg to perform a query such as

SELECT * FROM INFORMATION_SCHEMA.TABLES

在我的Java代码中是

吗?我是否必须创建一个视图,是否可以通过jooq-meta或其他方式访问该模式,还是需要向jooq-codegen使用的属性文件中添加一些内容(在生成的表类中未创建information_schema) ?还是其他?

from within my java code? Do I have to create a view, can the schema be accessed through jooq-meta or some other means, or do I need to add something to the property file used by jooq-codegen (information_schema isn't created in the generated tables classes)? Or something else?

这是我第一次尝试使用jooq,并且来自MySQL背景.我要有效地实现的目标是能够运行一些单元测试,以确保与数据库相关的代码能够正常工作.因此,我想访问数据库的元数据(模式)并返回某些内容,而不必知道是否存在任何用户创建的表.

This is my first foray into using jooq and am coming from a MySQL background. What I'm effectively trying to achieve is to be able to run some unit tests to ensure DB related code works. So I want to access the database's metadata (schema) and return something without having to know if any user created tables exist.

推荐答案

您可以像为其他任何架构一样为INFORMATION_SCHEMA生成类.实际上,jOOQ-meta包含对数据库架构进行逆向工程所需的一些类.

You can generate classes for the INFORMATION_SCHEMA just as any other schema. In fact, jOOQ-meta contains some of those classes required for reverse-engineering your database schema.

有关高级代码生成属性的手册部分提到了如何配置代码生成器加载几个输入模式":

The manual's section about advanced code generation properties mentions how you can configure the code generator to load several "input schemata":

<database>
  <schemata>
    <schema>
      <inputSchema>...</inputSchema>
    </schema>
    [ <schema>...</schema> ... ]
  </schemata>
</database>

这篇关于访问H2数据库架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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