SQL `NULL` 在第 1 列读取(JDBC 类型 null)但映射到非 Option 类型

SQL `NULL` read at column 1 (JDBC type null) but mapping is to a non-Option type

我想要 select 使用此查询的最大值(table 中的所有字段都不为空):

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

我知道,table 可能是空的,所以我使用这个: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),相同的查询可以正常工作

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

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