jOOQ insert/update 来自数据 class
jOOQ insert/update from data class
jOOQ 有一个很好的功能,可以让您将结果映射到数据中 class:
data class User(id: Int, email: String)
val users: List<User> = ctx.select().from(USERS).fetchInto(User::class.java)
是否有类似的方法来使用数据 class 的自动数据映射来编写 insert
?
update
怎么样?
调用各种“into”方法的逆运算,例如ResultQuery.fetchInto(Class)
is to load data into a record using various "from" methods, e.g. Record.from(Object)
or DSLContext.newRecord(Table, Object)
,所以:
val user: User = ...
val record: UserRecord = ctx.newRecord(USERS, user);
// Using statements
ctx.insertInto(USERS).set(record).execute();
ctx.update(USERS).set(record).where(...).execute();
// Using UpdatableRecord. See Javadoc about each one of these:
record.insert();
record.update();
record.store();
record.merge();
由于您的数据 class 没有“脏标志”的概念,这将始终将 UserRecord
中的所有值设置为 Record.changed() == true
。如果需要,您可以重置已更改的标志。
jOOQ 有一个很好的功能,可以让您将结果映射到数据中 class:
data class User(id: Int, email: String)
val users: List<User> = ctx.select().from(USERS).fetchInto(User::class.java)
是否有类似的方法来使用数据 class 的自动数据映射来编写 insert
?
update
怎么样?
调用各种“into”方法的逆运算,例如ResultQuery.fetchInto(Class)
is to load data into a record using various "from" methods, e.g. Record.from(Object)
or DSLContext.newRecord(Table, Object)
,所以:
val user: User = ...
val record: UserRecord = ctx.newRecord(USERS, user);
// Using statements
ctx.insertInto(USERS).set(record).execute();
ctx.update(USERS).set(record).where(...).execute();
// Using UpdatableRecord. See Javadoc about each one of these:
record.insert();
record.update();
record.store();
record.merge();
由于您的数据 class 没有“脏标志”的概念,这将始终将 UserRecord
中的所有值设置为 Record.changed() == true
。如果需要,您可以重置已更改的标志。