2

我想用 slick 连接一个 postgresql 数据库,但我的问题是如何表示这样的表:

    Column    |            Type             | Modifiers | Storage  | Description
--------------+-----------------------------+-----------+----------+-------------
 id           | bigint                      | not null  | plain    |
 version      | integer                     | not null  | plain    |
 tstamp       | timestamp without time zone | not null  | plain    |
 tags         | hstore                      |           | extended |
 nodes        | bigint[]                    |           | extended |

如果有人提示如何更换?在

object Ways extends Table[(?, Int, Int, java.sql.Timestamp, ?, ?, ?)]("WAYS") {
  def id = column[?]("id", O.PrimaryKey)
  def version = column[Int]("version")
  def user_id = column[Int]("user_id")
  def tstamp = column[java.sql.Timestamp]("tstamp")
  def changeset_id = column[?]("changeset_id")
  def tags = column[?]("tags")
  def nodes = column[?]("nodes")
  }

Array[String]是一个解决方案吗?

4

1 回答 1

3

slick-pg是解决这个问题的扩展:

import com.github.tminglei.slickpg._
trait ImplicitsPlus extends Implicits
                        with ArrayImplicits
                        with RangeImplicits
                        with HStoreImplicits
                        with SearchImplicits
                        with PostGISImplicits
  override val Implicit = new ImplicitsPlus {}
  override val simple = new SimpleQLPlus {}

  //////
  trait ImplicitsPlus extends Implicits
                        with ArrayImplicits
                        with RangeImplicits
                        with HStoreImplicits
                        with SearchImplicits
                        with PostGISImplicits

  trait SimpleQLPlus extends SimpleQL
                        with ImplicitsPlus
                        with SearchAssistants
}

object MyPostgresDriver extends MyPostgresDriver

object TestTable extends Table[Test](Some("xxx"), "Test") {
  def id = column[Long]("id", O.AutoInc, O.PrimaryKey)
  def during = column[Range[Timestamp]]("during")
  def location = column[Point]("location")
  def text = column[String]("text", O.DBType("varchar(4000)"))
  def props = column[Map[String,String]]("props_hstore")
  def tags = column[List[String]]("tags_arr")
}
于 2013-07-10T12:13:48.667 回答