【问题标题】:Slick Codegen With SQLServer and dbo Schema使用 SQLServer 和 dbo 架构的 Slick Codegen
【发布时间】:2017-07-14 12:14:23
【问题描述】:

我正在尝试使用 slick codegen 基于 SQLServer 中的现有数据创建一个 Tables.scala 文件,并具有以下设置:

slick.codegen.SourceCodeGenerator.main(Array("slick.jdbc.SQLServerProfile", 
                                             "com.microsoft.sqlserver.jdbc.SQLServerDriver",
                                             "jdbc:sqlserver://myserver.com:1433;applicationName=TestCodeGen;integratedSecurity=true;authenticationScheme=NativeAuthentication;databaseName=MYDB", 
                                             "src/main/scala/", 
                                             "com.mypackage", 
                                             "myUserId", 
                                             ""))

当我运行命令时,我没有收到任何错误,但会生成一个空的 Tables.scala 文件(数据库中有几十个表):

package com.mypackage
// AUTO-GENERATED Slick data model
/** Stand-alone Slick data model for immediate use */
object Tables extends {
  val profile = slick.jdbc.SQLServerProfile
} with Tables

/** Slick data model trait for extension, choice of backend or usage in the cake pattern. (Make sure to initialize this late.) */
trait Tables {
  val profile: slick.jdbc.JdbcProfile
  import profile.api._
  import slick.model.ForeignKeyAction

  /** DDL for all tables. Call .create to execute. */
  lazy val schema: profile.SchemaDescription = profile.DDL(Nil, Nil)
  @deprecated("Use .schema instead of .ddl", "3.0")
  def ddl = schema
}

我的怀疑是 SQLServer 使用 dbo 架构但该架构未在 codegen 调用中的任何位置指定这一事实存在问题(所有表都命名为“dbo..TableName”)。

所以我的问题是:我需要在 codegen 配置中的某处指定“dbo”吗?如果需要,怎么做?

如果答案是不需要做任何事情,那么我该如何调试 codegen 显然失败但没有产生错误的事实?

提前感谢您的考虑和回复。

【问题讨论】:

    标签: scala slick slick-codegen


    【解决方案1】:

    虽然对于直接连接,com.microsoft 驱动程序确实可以工作,但我发现要生成代码,您需要使用 $ 传入光滑的 jdbc SQLServerProfile。

    Array("slick.jdbc.SQLServerProfile", 
            "slick.jdbc.SQLServerProfile$",
            "jdbc:sqlserver://myserver.com:1433;applicationName=TestCodeGen;integratedSecurity=true;authenticationScheme=NativeAuthentication;databaseName=MYDB", 
            "src/main/scala/", 
            "com.mypackage", 
            "myUserId", 
            "")
    

    如果这不起作用,请尝试将 jtds 驱动程序添加到您的库中,并使用 jtds 样式的 url:

    "jdbc:jtds:sqlserver://myserver.com:1433;applicationName=TestCodeGen;integratedSecurity=true;authenticationScheme=NativeAuthentication;databaseName=MYDB"
    

    您的 jtds 依赖项如下所示:

    libraryDependencies += "net.sourceforge.jtds" % "jtds" % "1.3.1"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-07
      • 2016-02-11
      • 1970-01-01
      • 1970-01-01
      • 2016-08-07
      • 1970-01-01
      • 2016-03-23
      相关资源
      最近更新 更多