Help us understand the problem. What is going on with this article?

SlickでのSession周り

More than 5 years have passed since last update.

こんなのがあった場合、

Model.scala
import play.api.db.DB
import play.api.Play.current
import scala.slick.driver.MySQLDriver.simple._
import scala.slick.jdbc._
import scala.language.postfixOps

case class Model(id:Int, name:String)

object Models extends Table[Model]("models") {

  def id      = column[Int]("id", O.PrimaryKey, O.AutoInc)
  def name = column[String]("name", O.NotNull, O DBType "varchar(100)")
  def * = id ~ name <> (Model.apply _, Model.unapply _)

  /** DBコネクション */
  val database = Database.forDataSource(DB.getDataSource())

  /** 登録 */
  def create(e: Model) = database.withTransaction { implicit session: Session =>
    Models.insert(e)
  }
}

Database.threadLocalSessionをimportするとimplicit ....がいらないらしい

Model.scala
import play.api.db.DB
import play.api.Play.current
import scala.slick.driver.MySQLDriver.simple._
import scala.slick.jdbc._
import Database.threadLocalSession
import scala.language.postfixOps

case class Model(id:Int, name:String)

object Models extends Table[Model]("models") {

  def id      = column[Int]("id", O.PrimaryKey, O.AutoInc)
  def name = column[String]("name", O.NotNull, O DBType "varchar(100)")
  def * = id ~ name <> (Model.apply _, Model.unapply _)

  /** DBコネクション */
  val database = Database.forDataSource(DB.getDataSource())

  /** 登録 */
  def create(e: Model) = database.withTransaction {
    Models.insert(e)
  }
}
cobonas
forcas
『FORCAS(フォーカス)』は、データ分析に基づいて成約確度の高いアカウントを予測し、マーケティングと営業のリソースをそのターゲットアカウントに集中する最新マーケティング手法「Account Based Marketing (ABM) 」の実践を強力にサポートするマーケティングプラットフォームを開発・提供してます。
https://www.forcas.com/overview/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした