DBQC for Java
Schema discovery generates typed DbqcSchema table and column handles. Those handles retain Java and SQL types, so normal query code never repeats a column name or constructs an expression node.
import static DbqcSchema.Restaurants.*;
The ordinary case
var ids = TABLE
.where(CITY, "New York")
.select(ID);
Generated values have their normal Java types. Passing the wrong type does not compile. DBQC equality is null-safe (IS NOT DISTINCT FROM); the compiler may emit = when nullability proves it equivalent.
Predicates and joins
Java cannot overload comparison operators, so generated columns expose typed .eq(), .neq(), .lt(), .lte(), .gt(), and .gte() methods:
var highValue = DbqcSchema.Restaurants.TABLE
.join(
DbqcSchema.Orders.TABLE,
DbqcSchema.Restaurants.ID.eq(DbqcSchema.Orders.RESTAURANT_ID))
.where(DbqcSchema.Orders.TOTAL.gt(new BigDecimal("100.00")))
.select(
DbqcSchema.Restaurants.NAME,
DbqcSchema.Orders.TOTAL)
.orderBy(Dbqc.desc(DbqcSchema.Orders.TOTAL));
There is no public col(...) or lit(...) ceremony in this path. Use .and(), .or(), and .not() to compose boolean expressions.
Runtime parameters
A parameter carries both its source and typed column:
var input = Dbqc.param("restaurantId", "uuid", UUID.class);
var byId = DbqcSchema.Restaurants.TABLE
.join(
input.source(),
DbqcSchema.Restaurants.ID.eq(input.column()))
.select(
DbqcSchema.Restaurants.ID,
DbqcSchema.Restaurants.NAME);
var compiled = byId.compile("psql");
System.out.println(compiled.sql);
System.out.println(compiled.paramOrder); // [restaurantId]
Bind runtime values in paramOrder; DBQC never interpolates them into SQL.
Aggregates and HAVING
var revenue = DbqcSchema.Orders.TABLE
.groupBy(DbqcSchema.Orders.RESTAURANT_ID)
.having(Dbqc.sum(DbqcSchema.Orders.TOTAL).gt(new BigDecimal("0.00")))
.select(
DbqcSchema.Orders.RESTAURANT_ID,
Dbqc.sum(DbqcSchema.Orders.TOTAL).as("revenue"));
Only computed output needs .as(...); generated columns already carry names.
Reusable queries and CTE ordering
var revenue = DbqcSchema.Orders.TABLE
.groupBy(DbqcSchema.Orders.RESTAURANT_ID)
.select(
DbqcSchema.Orders.RESTAURANT_ID,
Dbqc.sum(DbqcSchema.Orders.TOTAL).as("revenue"));
var revenueRestaurantId = Dbqc.column(
revenue, "restaurant_id", "uuid", UUID.class, false);
var revenueAmount = Dbqc.column(
revenue, "revenue", "numeric(12,2)", BigDecimal.class, false);
var ranked = DbqcSchema.Restaurants.TABLE
.join(revenue, DbqcSchema.Restaurants.ID.eq(revenueRestaurantId))
.where(revenueAmount.gt(new BigDecimal("1000.00")))
.select(DbqcSchema.Restaurants.NAME, revenueAmount);
Generated base-table fields remain zero-ceremony. A newly computed relational heading is declared once when Java needs a typed handle for it. DBQC derives the dependency DAG and emits CTEs in valid order.
Windows, JSON, and pagination
var feed = DbqcSchema.Orders.TABLE
.select(
DbqcSchema.Orders.ID,
Dbqc.rowNumber()
.overColumns(
List.of(DbqcSchema.Orders.RESTAURANT_ID),
Dbqc.desc(DbqcSchema.Orders.CREATED_AT))
.as("number"))
.page(25, 0, Dbqc.desc(DbqcSchema.Orders.CREATED_AT));
JSON expressions are named only at projection:
var contacts = DbqcSchema.Restaurants.TABLE.select(
DbqcSchema.Restaurants.ID,
DbqcSchema.Restaurants.METADATA.expr()
.jsonPathText("$.contact.email")
.as("email"));
Writes
Assignments retain the generated column type:
var created = DbqcSchema.Restaurants.TABLE.insert(
DbqcSchema.Restaurants.ID.set(UUID.randomUUID()),
DbqcSchema.Restaurants.NAME.set("Saffron"),
DbqcSchema.Restaurants.CITY.set("New York"));
var moved = DbqcSchema.Restaurants.TABLE.update(
DbqcSchema.Restaurants.ID.eq(restaurantId),
DbqcSchema.Restaurants.CITY.set("Brooklyn"));
var removed = DbqcSchema.Restaurants.TABLE.delete(
DbqcSchema.Restaurants.STATUS.eq("closed"));
The lower-level overloads add returning columns, insert-from-select, update-from, conflict policies, locks, transactions, and procedures without changing the wire model.
Compile and execute
var compiled = ranked.compile("psql");
try (var statement = connection.prepareStatement(compiled.sql)) {
bind(statement, compiled.paramOrder, runtimeValues);
try (var rows = statement.executeQuery()) {
// map rows using compiled.rowSchema
}
}
DBQC compiles and describes the result; JDBC executes it. Set DBQC_ENDPOINT and DBQC_KEY, or pass endpoint credentials to compile(...).
Escape hatch
rawExpr() and rawSource() exist for vendor features DBQC does not model. Keep them explicit and isolated so ordinary queries retain type checks, dependency ordering, and dialect portability.