Tuco
Tuco

Reputation: 1052

JOOQ: Get table and columns with string?

Hello I'm using JOOQ with Spring Boot and was wondering if there was a way to obtain a table and its columns with a string of their name? For example:

I want to be able to get a table by doing something like:

someObject.getTable("user")

Then using the result of that get method I also want to obtain all of that table's columns and be able to compare the column names to other strings. In other words if there is a way to get a table, can I also get the table's column names from that same object?

I would really appreciate any help with this.

Upvotes: 5

Views: 5847

Answers (2)

Anmol Deora
Anmol Deora

Reputation: 41

Yes. As correctly stated above, only one addition to further clarify the upcoming users, PUBLIC is your DefaultSchema, if you have with you, meta generated code. So,

Table<?> table = new DefaultSchema().getTable("user");

Upvotes: 1

Lukas Eder
Lukas Eder

Reputation: 221145

Yes you can:

Using the code generator

When you generate your schema, all this information is available to you from generated code. Just go to your schema and look for the table (case-sensitive!):

Table<?> table = PUBLIC.getTable("user");

And then:

Field<?>[] fields = table.fields();

Using org.jooq.Meta

If you don't have generated meta data, you can still look up things from your JDBC connection using DSLContext.meta(), from where you can navigate your schemas / tables / etc.

Upvotes: 10

Related Questions