How can I JOIN tables in different databases (on the same server) using Slick?

北慕城南 提交于 2019-12-11 09:58:10

问题


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.

Can someone show me how to do this in Slick?

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.


回答1:


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)
}

This should really be documented somewhere: https://github.com/slick/slick/issues/659



来源:https://stackoverflow.com/questions/21603506/how-can-i-join-tables-in-different-databases-on-the-same-server-using-slick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!