Repository navigation
feat: enforce exact and optional cardinality and name failing queries - #28
Merged
omer-cengel merged 2 commits intoSep 24, 2026
Merged
Conversation
A :one query now returns exactly one row and raises QueryCardinalityException, a QueryExecutionException subclass, when it returns no row or more than one, instead of returning null or the first row. The new :optional annotation is accepted wherever :one is and returns Optional<T>, empty when no row matches, failing when more than one row is returned. :many and :exec are unchanged. QueryExecutor now exposes queryOne, queryOptional, queryMany, and execute, each taking the generated repository class name and query name, and every execution and cardinality failure message names them. Generated code imports java.util.Optional only for an :optional query. The external sample gains an optional FindAuthor lookup in place of its null missing-row checks, and release verification requires it.
omer-cengel
deleted the
feature/exact-and-optional-query-cardinality
branch
September 24, 2026 22:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A
:onequery no longer returnsnullwhen no row matches or silently returns the first of several rows. It now returns exactly one row or fails with a focusedQueryCardinalityException, and the new:optionalannotation covers zero-or-one lookups by returningOptional<T>. Every runtime execution and cardinality failure names the generated repository and query, so the application can tell which call failed.Changes
:onereturns its row directly and raisesdev.sqlcj.runtime.QueryCardinalityException(aQueryExecutionExceptionsubclass) when the query returns no row or more than one.:optionalannotation, accepted for aSELECTor a write withRETURNINGwherever:oneis. It returnsOptional.empty()for no row,Optional.of(row)for one, and raises the same exception for more than one.:manystill returnsList<T>(empty when no row matches) and:execstill returns the affected-row count.QueryExecutornow exposesqueryOne,queryOptional,queryMany, andexecute, each taking the repository class name and query name. Generated methods pass both as string literals.Query 'GetAuthor' in AuthorRepository returned no row; expected exactly oneandFailed to execute query 'GetAuthor' in AuthorRepository. Statements, result sets, and acquired connections are closed on a cardinality failure.java.util.Optionalonly when they declare an:optionalquery. Full-row:optionalqueries share the table's<TableName>Rowrecord.FindAuthorlookup in place of its null missing-row checks and shows the:onefailure, and release verification requires the new method.nullonly for a nullable column while row absence is expressed only by the annotation.Scope and non-goals
Optional, and no nullness annotations or new nullness type system are added.