从案例类中提取DDL

时间:2016-04-25 15:07:16

标签: scala scalikejdbc

我正在尝试使用scalikejdbc(试图从Slick转移),而且我一直坚持从实体创建我的架构(读取:案例类)。

// example Slick equivalent

case class X(id: Int, ...)

class XTable(tag: Tag) extends Table[X] (tag, "x") {
  def id = column[Int]("id")
  ... //more columns

  def * = (id, ...) <> (X.tupled, X.unapply)
}

val xTable = TableQuery[XTable]

db.run(xtable.schema.create) //creates in the DB a table named "x", with "id" and all other columns

似乎使用SQLSyntaxSupport可能是朝着正确方向迈出的一步,例如

// scalikejdbc

case class X (id: Int, ...)

object X extends SQLSyntaxSupport[X] {
  def apply (x: ResultName[X])(rs: WrappedResultSet): X = new X(id = rs.get(x.id, ...))
}

X.table.??? // what to do now?

但无法弄清楚下一步。

我正在寻找的是[逆向工程]中描述的工具的反面:http://scalikejdbc.org/documentation/reverse-engineering.html

任何帮助/想法,特别是对文档相关部分的指示,都将不胜感激

1 个答案:

答案 0 :(得分:0)

  

您可以使用statement语句获取SQL代码,例如   大多数其他基于SQL的操作。 Schema Actions是目前唯一的   可以产生多个声明的动作。

schema.create.statements.foreach(println)
schema.drop.statements.foreach(println)

enter image description here