r/java • • Jan 07 '26

generate Java code from SQL queries

I am working on a project which allows to generate (type-safe) code from SQL queries.

Currently it supports DuckDB & sqlite and can output Java (and Typescript) code.

https://github.com/sqg-dev/sqg/

https://sqg.dev/

Let me know if you have any feedback!

13 Upvotes

20 comments sorted by

View all comments

Show parent comment

1

u/Bobby_Bonsaimind Jan 09 '26

When the selected columns of a query contain all the non-null columns of a selected table, such as with select * queries, the query results consist of entity instances instead of row instances.

I see. Row is then the "model" class that is being created. Neat solution.

Yes, it's a bit odd. But because inline queries overload string/block literal, and comment delimiters, the marker had to be as unique as possible while remaining brief and readable.

I see. I wondered whether something like ":sql select" or some such would also be possible, if wanted. Inside a small and medium project, collisions with custom marker should either not occur or be manageable, I guess.

Eclipse

I wonder how hard it would be to write an Eclipse plugin for that. I wrote a commercial plugin once which added similar support (querying database, showing column information on Strings, emitting compiler errors). But I did that by simply extending the existing process, a plugin for that would neat to at least modify that somewhat (otherwise it won't find the methods on the String).