Compose dynamic queries using `and()` and `or()`
masterYou can build highly readable and composable queries by wrapping DSL expressions in functions that return Specification<T>. These functions can then be combined using and() and or() to create nested logic.
// 1. Define composable specification functions
fun hasName(name: String?): Specification<TvShow>? = name?.let { TvShow::name.equal(it) }
fun availableOnNetflix(available: Boolean?): Specification<TvShow>? = available?.let { TvShow::availableOnNetflix.equal(it) }
// 2. Combine them using and() and or()
val shows = tvShowRepo.findAll(
or(
and(
availableOnNetflix(false),
hasName("Jimmy")
),
and(
availableOnNetflix(true),
hasName("Killer")
)
)
)