dave08
11/30/2022, 12:18 PMToshihiro Nakamura
11/30/2022, 2:07 PMdave08
11/30/2022, 2:34 PMdave08
11/30/2022, 2:36 PM@KomappperEntity
definition (which is the real place to decide to which db it's related...)Toshihiro Nakamura
12/01/2022, 9:34 AMdave08
12/01/2022, 12:44 PM@KomapperEntity("db1")
annotation DB1Entity()
then use that in the entity's declaration, so that typos would be avoided...Toshihiro Nakamura
12/03/2022, 5:11 AM@KomapperEntity(unit = Db1::class)
is good. I have implemented this idea. Feel free to give me your opinion.
https://github.com/komapper/komapper/pull/794dave08
12/04/2022, 1:09 PMdave08
12/04/2022, 2:34 PMval db = JdbcDatabase<MyMetaObject>(config)
then the type could be used to validate and limit queries to it...?dave08
12/04/2022, 2:36 PM@KomapperEntity(unit = Db1::class)
annotation DB1Entity()
Toshihiro Nakamura
12/05/2022, 12:34 PM// Db1 is your meta object.
class Db1Access(private val db: JdbcDatabase, private val meta: Db1) {
operator fun <T> invoke(block: (JdbcDatabase, Db1) -> T): T {
return block(db, meta)
}
}
The above class is used as follows:
val db1Access = Db1Access(db, Db1)
val result = db1Access { db, meta ->
val a = meta.address
db.runQuery {
QueryDsl.from(a).where { a.id eq id }.first()
}
}
Toshihiro Nakamura
12/05/2022, 12:37 PM```@KomapperEntity(unit = Db1::class)
annotation DB1Entity()```Unfortunately, this style is not efficient.
dave08
12/05/2022, 12:39 PMThe following utility class will...Yeah, I guess, just with one extra level of nesting...
Unfortunately, this style is not efficient.Wow, I would have thought that compile-time KSP would handle such things easily... I wonder if there would be any other way to make this less error-prone and verbose. It's not a tremendously big deal... it's already better than what it is now, but still...