光滑的自定义codegen输出为空?

时间:2015-04-30 08:26:17

标签: scala jdbc slick codegen

我之前使用过codegen这样的光滑:

  

scala.slick.codegen.SourceCodeGenerator.main(   阵列(“com.typesafe.slick.driver.ms.SQLServerDriver”   “net.sourceforge.jtds.jdbc.Driver”   “JDBC:JTDS:SQLSERVER://10.0.1.12:1433;的databaseName =主人;”,   “/ home / bipin / slickcode”,“demo”,“user”,“pass”))

它生成可以连接到数据库的类。但我不需要所有的表只是其中的几个。所以我使用了一个自定义的光滑代码生成器,如下所示(取自https://github.com/slick/slick-codegen-customization-example/blob/master/codegen/CustomizedCodeGenerator.scala并修改):

import scala.slick.model.Model
import scala.slick.jdbc.meta.createModel
import com.typesafe.slick.driver.ms.SQLServerDriver

object CustomizedCodeGenerator{
  def main(args: Array[String]) = {
    codegen.writeToFile(
          "com.typesafe.slick.driver.ms.SQLServerDriver",
          "/home/bipin/slickcode",
          "demo"
        )
  }    
  val db = SQLServerDriver.simple.Database.forURL(
 "jdbc:jtds:sqlserver://10.0.1.12:1433;databaseName=master;user=user;password=pass;",
 driver="net.sourceforge.jtds.jdbc.Driver")
  // filter out desired tables
  val included = Seq("Table1","Table2","T3","T4")
  val model = db.withSession{ implicit session =>
    val tables = SQLServerDriver.getTables.list.filter(t => included contains t.name.name)
    tables.foreach(println);
    createModel( tables, SQLServerDriver )
  }
  val codegen = new scala.slick.codegen.SourceCodeGenerator(model){
    // customize Scala entity name (case class, etc.)
    override def entityName = dbTableName => dbTableName match {
      case "COFFEES" => "Coffee"
      case _ => super.entityName(dbTableName)
    }
    // customize Scala table name (table class, table values, ...)
    override def tableName = dbTableName => dbTableName match {
      case "COF_INVENTORY" => "CoffeeInventory"
      case _ => super.tableName(dbTableName)
    }
    // override generator responsible for tables
    override def Table = new Table(_){
      table =>
      // customize table value (TableQuery) name (uses tableName as a basis)
      override def TableValue = new TableValue{
        override def rawName = super.rawName.uncapitalize
      }
      // override generator responsible for columns
      override def Column = new Column(_){
        // customize Scala column names
        override def rawName = (table.model.name.table,this.model.name) match {
          case ("T3","@Column1") => "Column1"
          case _ => super.rawName
        }
      }
    }
  }
}

但是当我运行它时,输出文件没有任何表ddl。

  /** DDL for all tables. Call .create to execute. */
  lazy val ddl = 

任何人都可以告诉我我做错了什么以及如何解决它。感谢

0 个答案:

没有答案