【问题标题】:How to manually mapping String to postgresql text instead of just varchar(254)?如何手动将字符串映射到 postgresql 文本而不仅仅是 varchar(254)?
【发布时间】:2014-04-15 06:56:02
【问题描述】:

我用的是 slick2+postgresql 9.3+playframework 2

我的数据模型是:

class Page(tag:Tag) extends Table[(Long,Long, String,String,String, Option[Long], Option[Long])](tag, "Page"){
  def id=column[Long]("ID", O.PrimaryKey)
  def subId=column[Long]("subject")
  def title=column[String]("Title", O.NotNull)
  def describe=column[String]("Describe")
  def profile=column[String]("Profile")
  def icon=column[Long]("icon")
  def resId=column[Long]("Picture")
  def * = (id, subId,title, describe, profile,icon.?, resId.?)
  def page_sub=foreignKey("PA_SU_FK", subId, subject)(_.id)
  def page_res=foreignKey("PA_RE_FK", resId, resource)(_.id)

}

问题是描述的列是字符串,将在数据库中映射为 varchar(254)。但实际上,这个专栏可能很长,我的意思是它可能有 1000-3000 个字符。 如何手动将其映射到 Datamodel 中的文本?

【问题讨论】:

    标签: postgresql scala slick slick-2.0


    【解决方案1】:

    这应该适用于PostgreSQL

    def profile=column[String]("Profile",  O.DBType("TEXT"))
    

    或者你可以建立一个自定义的TypeMapper,我从来没有建立过,但是周围有很多帖子,比如this SO question 或this question。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多