dave08
12/07/2022, 10:27 AMsingle() 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...Toshihiro Nakamura
12/07/2022, 12:37 PMwhereas toList() is called on the flowQueryWhich
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 puzzlingThey are just utility functions. You can write a more concise DSL if you wish:
// 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:
val a = Meta.address
val address = db.runQuery {
from(a).where { a.addressId eq 1 }.first()
}dave08
12/07/2022, 12:40 PMToshihiro Nakamura
12/07/2022, 12:57 PMFlow.toList() is inconsistent? It is unrelated to Komapper’s API.dave08
12/07/2022, 1:02 PMdb.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 resultdave08
12/07/2022, 1:04 PMrunFlowQuery or maybe just an overload of runQuery might be a bit more consistent.dave08
12/07/2022, 1:06 PMdave08
12/07/2022, 1:19 PMdb.queryToFlow() and db.runQuery() would make things MUCH clearer...dave08
12/07/2022, 1:20 PMToshihiro Nakamura
12/07/2022, 1:48 PMflowQuery() is a function to convert a Query to a Flow. queryToFlow() may be easier to understand than flowQuery().dave08
12/07/2022, 1:49 PMdave08
12/07/2022, 1:53 PMqueryFlow() , or toQueryFlow() ...