Adam Jarvis
06/05/2025, 4:24 PMwhere
to be closer to andWhere
?
fun where(predicate: Op<Boolean>): Query {
where?.let {
error("WHERE clause is specified twice. Old value = '$it', new value = '$predicate'")
}
where = predicate
return this
}
^ to me, I end up just using andWhere
everywhere because of the built in handling of chaining
fun Query.andWhere(andPart: SqlExpressionBuilder.() -> Op<Boolean>) = adjustWhere {
val expr = Op.build { andPart() }
if (this == null) expr else this and expr
}
Why always throwing the error for chaining where
?Luis Arcos
06/06/2025, 2:29 PMwhere
is make the code look more like SQL, so no chaining is necessary.
.where {
(StudentAdvisorTable.institutionId eq institutionId)
.and(StudentAdvisorTable.advisorId eq advisorId)
}
Adam Jarvis
06/10/2025, 8:27 AMwheres
where you have one condition per, you should do andWhere
all the time?Adam Jarvis
06/10/2025, 8:32 AMwhere
respect the null state
Currently, I have a library function that provides a function which accepts an operation on a Query
override suspend fun filter(block: Query.(ThingDatabase) -> Query): List<Thing> {
val query = block(ThingDatabase.selectAll(), ThingDatabase)
// other things
query.andWhere {
// extra queries
}
}
I use andWhere
because I anticipate the end user using the injected query and using a where
on itBogdan
06/13/2025, 8:30 PMTable.selectAll()
.where { /* code */ }
.andWhere { }
.orWhere { }
helps to break up large conditions or is convenient for dynamic queries, the query can be collected in different places in the codeAdam Jarvis
06/13/2025, 8:56 PMwhere
has been called yet