postgresql - 如何将 Duration 类型映射到 Interval?
问题描述
我正在创建一个包含一个Interval
字段的 Slick Postresql 表,我想将其表示为Duration
case class Object(id: String, aproxDuration: Duration)
class Objects(tag: Tag) extends Table[Object](tag, "OBJECTS"){
def id = column[String]("id", O.PrimaryKey)
def expectedDuration = column[Duration]("expected_duration")
def * = (id, expectedDuration) <> (Object.tupled, Object.unapply)
}
为了支持这一点,我安装了slick-pg
扩展并创建了一个扩展的配置文件,ExPostgresProfile, PgDate2Support, PgRangeSupport
但我不确定为什么它没有找到隐含TypedType
的Duration
解决方案
import java.time.Duration
import com.github.tminglei.slickpg.{ExPostgresProfile, PgDate2Support}
import slick.lifted.ProvenShape
trait MyPostgresProfile extends ExPostgresProfile with PgDate2Support {
override val api = MyAPI
object MyAPI extends API with DateTimeImplicits
}
object MyPostgresProfile extends MyPostgresProfile
case class Object(id: String, aproxDuration: Duration)
object Tables {
import MyPostgresProfile.api._
class Objects(tag: Tag) extends Table[Object](tag, "OBJECTS") {
def id: Rep[String] = column[String]("id", O.PrimaryKey)
def expectedDuration: Rep[Duration] = column[Duration]("expected_duration")
def * : ProvenShape[Object] = (id, expectedDuration) <> (Object.tupled, Object.unapply)
}
}
推荐阅读
- arrays - Kotlin - Concatenate values of multi-dimensional arrays
- jenkins - How can I build both pull requests and merges to master with a single Jenkins pipeline build?
- node.js - 格式化数据以适应 GraphQL 模式
- php - Yii 1 Select2 从更新表单中获取选定的值
- sql - 在 Oracle 中执行脚本时 nextval 不起作用
- html - CSS 设计未显示在实时网站上
- rest - 如何使用 Docker Registry HTTP API V2 获取 docker 注册表中所有存储库的列表?
- python - 传递给 numpy.einsum() 的下标是什么意思?
- excel - 嵌套 IF 语句后循环不再起作用
- python - 当我尝试使用代理连接到站点时,我没有收到任何数据