我有一个可选的插入查询:
val q = sql"insert into some_table (some_field) select 42 where ...(some condition)"
使用以下命令运行此查询:
q.update.withUniqueGeneratedKeys[Option[Long]]("id")
失败了
结果集已用尽:预计会有更多行
那么condition
是假的。
如何Optional[Long]
使用 Doobie 从插入语句中获取结果?
UPD
.withGeneratedKeys[Long]("id")
只是Long
为了理解
val q = sql"insert into some_table (some_field) select 42 where ...(some condition)"
for {
id <- q.update.withGeneratedKeys[Long]("id") // id is long
_ <- if (<id is present>) <some other inserts> else <nothing>
} yield id
如何检查id
?