https://kotlinlang.org logo
#komapper
Title
# komapper
d

dave08

10/15/2023, 4:34 PM
Ok, it seems like that AS there is only supported from Mysql version 8.0.20... could you maybe provide an option to not include that alias for less than 8? Or is there a workaround for this?
In the meanwhile I used
executeScript()
but that's not ideal, since I can't re-use Komapper's generated entities... I'd really like to have the naming of the tables and fields in one place and not spread out in the code... Maybe having some kind of public api to re-use entity definitions even when writing sql's for
executeScript()
? For now, it seems a bit complex... it was really written for internal dialect classes and not the end-user.
t

Toshihiro Nakamura

10/16/2023, 11:14 AM
Komapper supports MySQL version 8 and above. As a workaround, you can create a custom Dialect.
d

dave08

10/16/2023, 11:26 AM
Can I just use the current one and swap the implementation for the upsert?
It might also be nice to have a bit of documentation in the source code... if someone would want to contribute or even just understand something there, it's currently a bit hard... like what's cutBack()?
t

Toshihiro Nakamura

10/16/2023, 11:43 AM
Can I just use the current one and swap the implementation for the upsert?
Please extend
MySqlR2dbcDialect
, override
getEntityUpsertStatementBuilder
, and return a customized implementation of
EntityUpsertStatementBuilder
.
👍🏼 1
d

dave08

10/16/2023, 11:47 AM
I need to remove the cutBack too?
Copy code
buf.append(" (")
        for (p in properties) {
            column(p)
            buf.append(", ")
        }
        buf.cutBack(2)
        buf.append(") values ")
        for (entity in entities) {
            buf.append("(")
            for (p in properties) {
                buf.bind(p.toValue(entity))
                buf.append(", ")
            }
            buf.cutBack(2)
            buf.append("), ")
        }
        buf.cutBack(2) /// ***This cutBack***
        buf.append(" as ")
        table(excluded, TableNameType.ALIAS_ONLY)
It seems to remove unnecessary things from the sql, but I'm not sure exactly what and how...
t

Toshihiro Nakamura

10/16/2023, 11:51 AM
cutBack
removes a specified number of characters from the SQL string buffer. This is a necessary operation here, so it should not be removed from the code.
d

dave08

10/16/2023, 11:51 AM
Even though I'm removing
Copy code
buf.append(" as ")
        table(excluded, TableNameType.ALIAS_ONLY)
(which are the lines that seem to be causing problems with Mysql 5.7)
t

Toshihiro Nakamura

10/16/2023, 11:55 AM
You should be able to simply remove the following two lines. Give it a try.
Copy code
buf.append(" as ")
table(excluded, TableNameType.ALIAS_ONLY)
3 Views