如何手动将String映射到postgresql文本而不仅仅是varchar(254)?

前端之家收集整理的这篇文章主要介绍了如何手动将String映射到postgresql文本而不仅仅是varchar(254)?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用slick2 postgresql 9.3 playframework 2

我的数据模型是:

class Page(tag:Tag) extends Table[(Long,Long,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",subject)(_.id)
  def page_res=foreignKey("PA_RE_FK",resId,resource)(_.id)

}

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

这适用于Postgresql
def profile=column[String]("Profile",O.DBType("TEXT"))

或者你可以建立一个自定义的TypeMapper,我从来没有建立一个,但有很多帖子,如this SO问题或this问题.

希望能帮助到你.

猜你在找的Postgre SQL相关文章