Skip to main content

Monthly Update - 2026-01

ยท One min read

A clean start to the new year with a focused enhancement to the Expression API.

Changesโ€‹

teaql-spring-boot-starterโ€‹

๐Ÿš€ Adding orElse and orElseThrow to Expressionโ€‹

The Expression class now supports orElse() and orElseThrow() methods, bringing a familiar Optional-like API to TeaQL's query expression system. This makes it easier to handle cases where a query expression might not resolve to a value.

+ Expression.orElse(defaultValue): returns default when expression is empty
+ Expression.orElseThrow(supplier): throws exception when expression is empty
+ 28 lines added to Expression.java

Example:

// Get a value with a default fallback
String name = Q.user().name().orElse("Unknown");

// Throw a custom exception if value is not found
String email = Q.user().email()
.orElseThrow(() -> new BusinessException("Email is required"));

This pattern aligns TeaQL's expression API with Java's Optional conventions, making it more intuitive for developers already familiar with the standard library.

API Design

The orElse and orElseThrow methods follow the same contract as java.util.Optional:

  • orElse(T other) โ€” returns the value if present, otherwise returns other
  • orElseThrow(Supplier<? extends X> exceptionSupplier) โ€” returns the value if present, otherwise throws an exception produced by the supplier

This consistency reduces the learning curve and makes TeaQL expressions feel like natural Java.