Hi Bjoern,

Do note that SELECT * is not explicitly supported by jOOQ yet. The feature
is on the roadmap, but it isn't really essential to every day jOOQ usage:
https://github.com/jOOQ/jOOQ/issues/2769

What you can certainly do is pass several fields to the select() clause in
one go, e.g.:

ctx.select(MY_TABLE.fields())


This mostly has the same effect as SELECT *, except that it will be
explicitly listing the fields. If you're using the code generator to
generate MY_TABLE, then using selectFrom(MY_TABLE) will generate all those
fields as well in the SQL statement, as they are known to jOOQ.

jOOQ only generates SELECT * in the generated SQL, if you don't specify any
explicit SELECT columns and one of the tables in the FROM clause has
unknown columns.

However, if you want to apply your custom converter, you simply have to
tell jOOQ what columns you're selecting, explicitly.

2017-07-11 13:42 GMT+02:00 <[email protected]>:
>
> One remark: do you think it is smart to have all those overloaded methods
> (for J5+)? Especially since varargs. It makes thinks (in code completion)
> hard to read, JavaDoc bloatet, etc.. Also, now I may have to import a
> Record2, a Record4, a Record5, and what if at any time I would need a
> Record326?
>

Those are many questions, and yes of course, it is "smart". :) Whether you
like that is a different story, but this approach has added tons of value
since jOOQ 3.0, and I'm taking bets you'll like it eventually.

jOOQ has been exploring the possibilities of modelling SQL as an internal
domain-specific language for quite a while now. If you use SQL as an
external DSL, the parser would offer exactly the same number of
"overloads", except that being an external DSL with specific tooling made
for that language, you wouldn't see the "bloat" in things like code
completion, because the tooling can apply domain knowledge. But then again,
you'd be using an *external* DSL, so you don't have any of that Java
compile-time type safety that jOOQ users love so much about jOOQ.

Let's look at your different ideas individually:

(for J5+)


I'm not sure what Java 5 has to do with this. Generics? They're a great
enabler for the jOOQ API, indeed.

Especially since varargs.


You probably mean select() here, right? You'd prefer to have only that
single select(Field<?>...) method, not the select(Field<T1>, Field<T2>,
..., Field<TN>) overloads.

But guess what, this type safety is really useful in many cases, e.g.

- Unions are type safe
- The IN predicate is type safe
- Correlated subqueries are type safe
- ROW predicates are type safe
- Results (up to degree 22) are type safe

Especially the latter is extremely useful in languages whose type inference
mechanisms are stronger than Java's. Take Kotlin and jOOQ 3.10, for
instance:

for ((first, last, title) in ctx
   .select(a.FIRST_NAME, a.LAST_NAME, b.TITLE)
   .from(a)
   .join(b).on(a.ID.eq(b.AUTHOR_ID))
   .orderBy(1, 2, 3))
       println("$title by $first $last")

In the example above, the type of the local variables "first", "last", and
"title" can be inferred by the Kotlin compiler to be String. Awesome, isn't
it? Even without type inference (if you prefer explicit type declarations)
you could still profit from type safety. Whenever you change an expression
in your SQL statement (or even when you add / remove a column), your
compiler will indicate an error. I personally wouldn't want to miss that.

Details here:
https://blog.jooq.org/2017/05/18/10-nice-examples-of-writing-sql-in-kotlin-with-jooq/

It makes thinks (in code completion) hard to read


Yes, code completion does offer many options. You probably mean select().
That's a relatively low price to pay for the nice features we're getting
out of it, see comments above.

JavaDoc bloatet


Hmm, could anything be improved here?

Also, now I may have to import a Record2, a Record4, a Record5, and what if
> at any time I would need a Record326?


We chose the "pragmatic" approach and stopped at degree 22 (like the Scala
language). If you select a 23rd column, then the varargs
select(Field<?>...) method will be the only applicable method to the
compiler, and you'll get a Record without any degree and column type
information.

I hope this helps.
Lukas

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to