Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manually mapping String to postgresql text instead of just varchar(254)?

I use slick2+postgresql 9.3+playframework 2

My data model is:

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)

}

the problem is the column describe is String and will be mapping as varchar(254) in database. But actually, this column may very very long, I mean it may 1000-3000 characters. how to manually mapping it to text in Datamodel?

like image 451
user504909 Avatar asked Oct 21 '22 10:10

user504909


1 Answers

This should work for PostgreSQL:

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

Or you could build a custom TypeMapper, I never built one but there are a lot of posts around, like this SO question or this question.

Hope it helps.

like image 139
Ende Neu Avatar answered Oct 23 '22 01:10

Ende Neu