Queries
Storm provides a powerful and flexible query API. All queries are type-safe; the generated metamodel (User_, City_, etc.) catches errors at compile time rather than at runtime.
Key features:
- Compile-time checked -- field references are validated by the metamodel
- No string-based queries -- no risk of typos in column names
- Single-query loading -- related entities load in JOINs, not N+1 queries
- Two styles -- quick methods for simple cases, fluent builder for complex queries
Choosing a Query Approach
Storm offers three ways to query data, each suited to different complexity levels:
| Approach | Best for | Type safety | Flexibility |
|---|---|---|---|
Repository findBy | Simple key lookups by primary key or unique key | Full compile-time | Low (single-field equality only) |
| Query DSL | Filtering, ordering, pagination with type-safe conditions | Full compile-time | Medium (AND/OR predicates, joins, ordering) |
| SQL Templates | Complex joins, subqueries, CTEs, window functions, database-specific SQL | Column references checked at compile time, SQL structure at runtime | High (full SQL control) |
Start with the simplest approach that meets your needs. Use findBy or findAll for straightforward lookups. Move to the query builder when you need compound filters or pagination. Use SQL templates when you need SQL features the DSL does not cover.