我想使用 Slick
在 Scala
的 Amazon Redshift
实例上建立连接。
我应该使用哪个驱动程序以及如何使用 sbt
和 Slick
进行设置?
最佳答案
我们可以使用Amazon's Redshift driver for Java并将其包含到 build.sbt
中(请参阅 release note 了解当前版本):
resolvers ++= Seq(
"Redsfhit" at "http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release"
)
libraryDependencies += "com.amazon.redshift" % "redshift-jdbc42" % "1.2.10.1009"
让我们也包括 Slick
dependencies :
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "3.2.3",
"org.slf4j" % "slf4j-nop" % "1.6.4",
"com.typesafe.slick" %% "slick-hikaricp" % "3.2.3"
)
一种方法 configure the connection with Slick
包括使用类型安全配置
。让我们使用您的 Redhsift
设置在 src/main/resources/
中创建 application.conf
:
my_redshift {
url = "jdbc:redshift://examplecluster.abc123xyz789.us-west-2.redshift.amazonaws.com:5439/dev"
user = my_user
password = my_password
driver = com.amazon.redshift.jdbc.Driver
connectionPool = disabled
keepAliveConnection = true
}
我们最终可以从 Scala 加载此配置(my_redshift
是您在类型安全配置中选择的根目录):
import slick.jdbc.PostgresProfile.api._
val db: Database = Database.forConfig("my_redshift")
关于scala - 如何与 Slick 建立 Redshift 连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52266267/