So far, komapper seems very nice! (I started using...
# komapper
d
So far, komapper seems very nice! (I started using it a new microservice...) I'm still wondering about a few seeming inconsistencies... like the
single()
being called on the Query, whereas
toList()
is called on the flowQuery... also the presence of the lamba form of runQuery and flowQuery is a bit puzzling... it even only has an empty receiver object...
t
Thanks for using Komapper.
whereas toList() is called on the flowQuery
Which
toList()
is it?
org.komapper.core.dsl.query.FlowQuery
doesn’t have the function of that name.
the presence of the lamba form of runQuery and flowQuery is a bit puzzling
They are just utility functions. You can write a more concise DSL if you wish:
Copy code
// define your extension function
fun <ENTITY : Any, ID : Any, META : EntityMetamodel<ENTITY, ID, META>> QueryScope.from(metamodel: META): SelectQueryBuilder<ENTITY, ID, META> {
    return QueryDsl.from(metamodel)
}
Use the above extension function in the
runQuery
lambda block:
Copy code
val a = Meta.address
val address = db.runQuery {
    from(a).where { a.addressId eq 1 }.first()
}
d
toList() on the Flow
t
I see. Why do you think the
Flow.toList()
is inconsistent? It is unrelated to Komapper’s API.
d
Compare:
Copy code
db.flowQuery(
            QueryDsl.from(oa).where { oa.deviceNo eq newDeviceNo }
        ).toList()
// To:
db.runQuery(QueryDsl.from(oa).where { oa.deviceNo eq deviceNo }.single())
// The single makes the user understand that he's actually recieving something even BEFORE the runQuery... the toList after the flowQuery makes it very clear that what's inside the flowQuery is JUST a query and NOT actually getting any result
It was a bit confusing in the beginning... although now I understand it to a certain point... I think the naming is a bit unclear also... maybe
runFlowQuery
or maybe just an overload of
runQuery
might be a bit more consistent.
Than flowQuery... I guess that's really the reason that there's the difference in my original question 🤕.
maybe
db.queryToFlow()
and
db.runQuery()
would make things MUCH clearer...
Or something similar to that idea...
t
flowQuery()
is a function to convert a Query to a Flow.
queryToFlow()
may be easier to understand than
flowQuery()
.
d
Yeah, after having tried to define the problem, I guess that's what bothered me from the beginning... 😊
Or maybe even
queryFlow()
, or
toQueryFlow()
...