Toshihiro Nakamura
08/11/2024, 2:12 PMOne
, Many
, and Exec
, each with corresponding extension functions generated by KSP for use with QueryDsl.
I would greatly appreciate it if you could take a look at the PR and share your thoughts. Your feedback will be invaluable in ensuring that this feature meets the needs of the community and integrates well with the existing framework.
You can find the PR here.
https://github.com/komapper/komapper/pull/1346
Thank you in advance for your time and input!dave08
08/11/2024, 2:50 PMdave08
08/11/2024, 3:39 PMval
there.dave08
08/11/2024, 3:42 PMsingleOrNull()
... sometimes I'd expect to have an answer, sometimes I need to know if it exists or not.dave08
08/11/2024, 3:43 PMRETURNING
...?Toshihiro Nakamura
08/11/2024, 4:00 PMI think you’d also have to deal withWe can write as follows:singleOrNull()
class GetAuthor(val id: Int) : One<Author?>({ selectAsAuthor().singleOrNull() })
Also, what about Inserts withFor now, the priority is low because the DSL already has a...?RETURNING
returning
function. https://www.komapper.org/docs/reference/query/querydsl/insert/#returning
Do we really need RETURNING
in SQL templates?dave08
08/11/2024, 4:02 PMdave08
08/12/2024, 6:47 AMdave08
08/12/2024, 6:48 AMdave08
08/12/2024, 6:50 AMdata class Pagination(val from: Int, val limit: Int)
that's nullable passed into queries and an enum for order by's. Could this support such parameters instead of having to make froms and limits and converting enums to strings everywhere?dave08
08/12/2024, 6:54 AM@KomapperCommand
@PaginatedCommand
with the sql prefixed or suffixed with common sql? Maybe this is all overkill, I'm just comparing to what we currently do with other frameworks...Toshihiro Nakamura
08/12/2024, 7:50 AMdave08
08/12/2024, 7:54 AMLIMIT ? OFFSET ?
conditionally, so we have util functions that do that for all queries that need it (and they automatically add the parameters to the parameter list). with the current templating feature, that code could also be appended to the string, but if the template is in an annotation it would have to be repeated for all our queries (and class params in One... etc..) ... same with order by.Toshihiro Nakamura
08/12/2024, 8:28 AM@KomapperCommand
are just an optional approach.dave08
08/12/2024, 8:34 AM@KomapperCommand("""
select name, age from person where age > 1 /*# orderBy */
""")
class GetPerson(orderBy: EmbeddedDirective): Many<Person>
Toshihiro Nakamura
08/12/2024, 9:04 AMorderBy
variable can be anything.dave08
08/12/2024, 9:07 AM@KomapperEmbeddedDirective("""LIMIT /*limit*/ OFFSET /*offset*/""")
class Pagination(val limit: Int, val offset: Int)
@KomapperCommand("""
select name, age from person where age > 1 /*# pagination */
""")
class GetPerson(pagination: Pagination?): Many<Person>
would that be possible?Toshihiro Nakamura
08/12/2024, 9:46 AMclass Pagination(val limit: Int, val offset: Int)
@KomapperCommand("""
select name, age from person where age > 1
/*%if pagination != null */
LIMIT /* pagination.limit */ OFFSET /*pagination.offset*/
/*%end*/
""")
class GetPerson(pagination: Pagination?): Many<Person>
dave08
08/12/2024, 9:49 AMdave08
08/12/2024, 9:51 AMdave08
08/12/2024, 10:03 AM/*%if pagination != null */
LIMIT /* pagination.limit */ OFFSET /*pagination.offset*/
/*%end*/
in the @KomapperCommand
's sql somehow... with a regular template query it's just a string, here it's an annotation... I wonder if this would work:
const val paginationTemplate = """
/*%if pagination != null */
LIMIT /* pagination.limit */ OFFSET /*pagination.offset*/
/*%end*/
"""
@KomapperCommand("""
select name, age from person where age > 1
$paginationTemplate
""")
class GetPerson(pagination: Pagination?): Many<Person>
Toshihiro Nakamura
08/13/2024, 5:03 AMconst
values, I introduced the @KomapperPartial
annotation.dave08
08/14/2024, 5:55 AMdave08
08/14/2024, 6:15 AMdave08
08/14/2024, 6:17 AM?
prepared statements... so that wouldn't allow putting a field name there to use in an ORDER BY?Toshihiro Nakamura
08/14/2024, 8:29 AM@KomapperCommand(
"""
select * from address where street = /*street*/'test' /*# orderBy */
""",
)
class GetByStreet(val street: String, val orderBy: String) : One<Address>({ select(asAddress).single() })
val query = QueryDsl.execute(GetByStreet("STREET 10", "order by address_id"))
dave08
08/14/2024, 8:30 AMdave08
08/14/2024, 8:32 AMORDER BY null
which might happen... it would be nicer to have an order by partial and be able to just specify the fields being ordered by...dave08
08/14/2024, 8:34 AMToshihiro Nakamura
08/14/2024, 9:47 AM/*%if orderByType == @example.OrderByType@A */
order by aaa
/*%elseif orderByType == @example.OrderByType@B */
order by aaa, bbb
/*%elseif orderByType == @example.OrderByType@C */
order by aaa, bbb, ccc
/*%end */
example.OrderByType
is an enum type.dave08
08/14/2024, 9:49 AMdave08
08/14/2024, 9:51 AM@Language("KomapperTemplate")
to Intellij... it seems like the syntax is complex enough that having a bit of highlighting and checking in the editor might be worth it.