如何使用 Slick 建立 Redshift 连接?
How to set up a Redshift connection with Slick?
我想在 Scala
的 Amazon Redshift
实例上与 Slick
建立连接。
我应该使用哪个驱动程序以及如何使用 sbt
和 Slick
进行设置?
当前版本我们可以使用Amazon's Redshift driver for Java and include it to the build.sbt
(see the 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
的一种方法是使用 typesafe config
。让我们使用您的 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
的 Amazon Redshift
实例上与 Slick
建立连接。
我应该使用哪个驱动程序以及如何使用 sbt
和 Slick
进行设置?
当前版本我们可以使用Amazon's Redshift driver for Java and include it to the build.sbt
(see the 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
的一种方法是使用 typesafe config
。让我们使用您的 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")