scala - SQL `NULL` 在第 1 列读取(JDBC 类型为空)但映射到非选项类型

标签 scala quill doobie quill.io

我想使用这个查询选择最大值(表中的所有字段都不为空):

dc.run(quote {
    query[SchemaInfo]
      .filter(_.subjectName == lift(subject))
      .map(_.version)
      .max
  }).map(_.map(_ + 1).getOrElse(1))

我知道,那个表可能是空的,所以我使用这个:map(_.map(_ + 1).getOrElse(1))

问题是这个查询产生了这个错误:

SQL NULL read at column 1 (JDBC type null) but mapping is to a non-Option type; use Option here. Note that JDBC column indexing is 1-based. doobie.util.invariant$NonNullableColumnRead: SQL NULL read at column 1 (JDBC type null) but mapping is to a non-Option type; use Option here. Note that JDBC column indexing is 1-based.

如何解决? 没有 quill(使用纯 doobie)相同的查询正常工作

最佳答案

我知道你可能已经得到了答案,但我会在这里留下我的评论,希望它能帮助将来的人。

所以问题是一致的 查询[SchemaInfo] 因为记录可能不存在,所以应该映射到 query[Option[SchemaInfo]].unique

关于scala - SQL `NULL` 在第 1 列读取(JDBC 类型为空)但映射到非选项类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57873699/

相关文章:

scala - Play Framework 依赖注入(inject)对象与 @Singleton 类

java - 尝试在 scala 中重写 getListCellRenderComponent 方法时出现对象创建不可能错误

javascript - 如何将 Quill.js 应用于已经内容可编辑的元素?

reactjs - React-Quill - 错误你很可能想要 `editor.getContents()`

postgresql - jdbc-HikariCP : Seeing low insert thoughput while DB/App cpu % is still low

scala - 使用泛型进行 Doobie 批量更新

scala - 这是在 Lift 中实现 GMail 小部件的正确方法吗?

memory - Scala 中的 BitSet 内存使用情况

javascript - 编辑器初始化后如何添加自定义颜色