dave08
12/13/2022, 4:37 PMToshihiro Nakamura
12/14/2022, 10:57 AM@KomapperEntity
data class EmployeeProject(
@KomapperId
@KomapperAutoIncrement
val id: Int,
val employeeId: Int,
val projectId: Int
)
or
@KomapperEntity
data class EmployeeProject(
@KomapperId
val employeeId: Int,
@KomapperId
val projectId: Int
)
dave08
12/14/2022, 10:58 AMToshihiro Nakamura
12/14/2022, 10:58 AMdave08
12/14/2022, 10:59 AM@KomapperId
can be used twice in the same class... it might be nice to point that out in the docs... I tried #1, but it's just too verbose for my case...dave08
12/14/2022, 11:00 AMdave08
12/14/2022, 11:01 AMToshihiro Nakamura
12/14/2022, 11:14 AMdave08
12/14/2022, 11:31 AMdave08
12/14/2022, 2:41 PMToshihiro Nakamura
12/14/2022, 3:26 PMQueryDsl.update(..).single(..)
require entity identifier.dave08
12/14/2022, 4:08 PMEntityMetamodelWithId
for those queries, but the others would be the base interface EntityMetamodel
without the id, then those functions wouldn't be able to be called.dave08
12/15/2022, 10:55 AMToshihiro Nakamura
12/15/2022, 12:28 PMI wonder if there’s any better solution, if what I proposed above is maybe a bit too much work.Yes, I feel it is a bit too much work. I don’t have any good ideas at the moment.
Toshihiro Nakamura
12/15/2022, 12:38 PM// define entity without id
@KomapperEntity(requiresId = false)
data class Person(...)
// get a metadata
val p = Meta.person
// when you try to run a query that needs id, Komapper throws exception
db.runQuery(QueryDsl.update(p).single(Person(...)))
dave08
12/15/2022, 12:55 PMdave08
12/15/2022, 12:57 PMlazt omen
12/16/2022, 8:11 AMdave08
12/16/2022, 10:09 AMToshihiro Nakamura
12/16/2022, 11:48 PM// Define a linker entity that has virtual IDs
@KomapperEntity
data class Belonging(
@KomapperId(virtual = true) val employeeId: Int,
@KomapperId(virtual = true) val departmentId: Int
)
// QueryDsl.create does not generate primary keys for virtual IDs.
db.runQuery {
// create table if not exists belonging (employee_id integer not null, department_id integer not null)
QueryDsl.create(Meta.belonging)
}
// In other operations, virtual IDs are treated like normal IDs.
db.runQuery {
// delete from belonging as t0_ where t0_.employee_id = 1 and t0_.department_id = 1
QueryDsl.delete(Meta.belonging).single(Belonging(1,1))
}
lazt omen
12/17/2022, 4:28 AMdave08
12/18/2022, 10:34 AMToshihiro Nakamura
12/24/2022, 4:58 AM