本文介绍了使用Slick在Playframework中创建MySQL连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用光滑的1.0.0连接到mysql数据库.

I'm trying to connect to a mysql database with slick 1.0.0.

到目前为止我所做的:

在我添加的Build.scala中

in Build.scala I've added

val appDependencies = Seq(
    anorm,
    "mysql" % "mysql-connector-java" % "5.1.24",
    "com.typesafe.slick" % "slick_2.10" % "1.0.0",
    "org.slf4j" % "slf4j-nop" % "1.6.4"
)

在application.conf

in application.conf

db.default.driver=com.mysql.jdbc.Driver
db.default.url="url to mysql db"
db.default.user=user
db.default.pass=password

,现在我正尝试从数据库读取条目.为此,我有一个模型

and now I'm trying to read an Entry from the DB. For this I have a model

package models

import scala.slick.driver.MySQLDriver.simple._
import Database.threadLocalSession

object Organisations extends Table[(Int, String)]("Organisation")
{
    def id = column[Int]("id", O.PrimaryKey)
    def name = column[String]("name")
    def * = id ~ name
}

现在我只想输出条目

val orgs =
    for { o <- Organisations } yield o.name

println("Length" + orgs.toString())

但是它不起作用.我敢肯定我犯了很多错误,但是似乎没有关于mysql的安迪教程.

But it doesn't work. I'm sure I've made plenty of errors, but there don't seem to be andy slick tutorials with mysql.

感谢您的耐心等待,我希望我的解释清楚.

Thank you for your patience and I hope my explanations are clear.

推荐答案

使用Slick需要一些样板文件,创建会话以及所有这些,并检出Fredrik Ekholdt(类型安全)编写的Play-Slick插件!

Using Slick requires a bit of boilerplate, creating session and all that, checkout the Play-Slick plugin written by Fredrik Ekholdt (typesafe)!

它为您完成了所有工作,并且在Wiki上有很好的示例来说明如何使用它.

It does all that plumbing for you and there are good examples on the wiki on how to use it.

https://github.com/freekh/play-slick/

这篇关于使用Slick在Playframework中创建MySQL连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 22:41