简体   繁体   English

在Slick中,有一种无需使用特定JDBC驱动程序即可声明表的方法

[英]In Slick is there a way to declar Tables without using a Specific JDBC Driver

In my persistence code all through out the tables, etc. I have the following import 在我的持久性代码中,遍及整个表等。我具有以下导入

import scala.slick.driver.PostgresDriver.simple._

This is nice because it works, but this is a problem because all my code is bound to Postgres exclusively. 这很不错,因为它可以工作,但是这是一个问题,因为我所有的代码都专门绑定到Postgres。 If I want my production to do Postgres and my test to be HSQLDB, for example, I can't. 例如,如果我希望我的产品执行Postgres,而我的测试是HSQLDB,则不能。 I'd like to declare which DataSource/Driver when I'm running my persistence manager (which will do the create) instead of at the table declaration. 我想在运行持久性管理器(它将执行创建操作)而不是在表声明时声明哪个DataSource / Driver。 What am I missing? 我想念什么?

This is certainly possible using the cake pattern. 当然,使用蛋糕图案是可能的。 My team uses H2 in development and MySQL in production. 我的团队在开发中使用H2,在生产中使用MySQL。

See MultiDBExample and MultiDBCakeExample in https://github.com/slick/slick-examples 请参阅https://github.com/slick/slick-examples中的 MultiDBExample和MultiDBCakeExample

As far as I was able to find, I think this is a definite restriction in Slick. 据我所知,我认为这是Slick中的明确限制。 So much so that I dropped my test environments database and switched it to the same type as my production one. 如此之多,以至于我删除了测试环境数据库,并将其切换为与生产环境相同的类型。 In retrospect, this is what I should have been doing in the first place, but I do understand this is sometimes easier said than done. 回想起来,这是我本来应该做的,但是我知道有时说起来容易做起来难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM