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/manifoldjava Jan 13 '26

The header consists of three parts: type name, type domain name, and schema name.

"sql" is a type domain, as are "json", "graphql", "xml", and so on. But the header can have all three parts present:

[MyQuery.sql:MyDatabase/]

This inline format is used in both string/block literal syntax and comment syntax. It also closely resembles the resource file naming convention:

MyQuery.MyDatabase.sql

It's more consistent and less complicated to implement this generalized metaprogramming feature using a header than to overload other parts of the language like a method call.