我如何在不同的数据库(在同一服务器上)使用Slick JOIN表? [英] How can I JOIN tables in different databases (on the same server) using Slick?

查看:338
本文介绍了我如何在不同的数据库(在同一服务器上)使用Slick JOIN表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一个MySQL服务器上使用Slick 2.0在不同数据库中的两个表上进行连接。通常这只是一个通过限定名称引用表的问题,例如。 DB1.TABLE1

I'd like to do a join on two tables residing in different databases on the same MySQL server, using Slick 2.0. Usually this would just be a matter of referring to the tables via a qualified name, e.g. DB1.TABLE1.


有人可以告诉我如何在Slick

Can someone show me how to do this in Slick?

如果我没有在JDBC连接字符串中指定数据库,我会收到异常。如果我指定其中一个数据库,请 DB1 ,并将 Table 构造函数中的表名称指定为 DB1.TABLE1 DB2.TABLE2 ,那么我得到一个关于缺少的表 DB1的异常。 DB2.TABLE2

If I don't specify a database in the JDBC connection string, I get an exception. If I do specify one of the databases there, say DB1, and specify the table name in the Table constructors as DB1.TABLE1 and DB2.TABLE2, then I get an exception about the missing table DB1.DB2.TABLE2.

推荐答案

在连接字符串中指定任何数据库, code>每个表类的模式参数。

Specify any database in the connection string and pass the database as the schema argument to Table for each table class.

class SomeTable(tag: Tag) extends Table[(Int,String)](
  tag, Some("SOME_DB"), "SOME_TABLE"
) {
  def id = column[Int]("id")
  def title = column[String]("title")
  def * = (id, title)
}

这应该在某处记录: https://github.com/slick/slick/issues/659

这篇关于我如何在不同的数据库(在同一服务器上)使用Slick JOIN表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆