LoginSignup
3
5

More than 5 years have passed since last update.

#PlayFramework Anormを使う

Last updated at Posted at 2017-06-06

Play FrameworkではAnormという便利なAPIがあって、そのAPIを追加する手順をサクッと紹介。

Anormとは

簡単に言うと、Payとデータベースのアクセスをよりシンプルかつ高機能に提供するもの。
SQL("SELECT * FROM users") のようにそのままコードに書くことができるので可読性も高く、パースなどの機能も提供する。

追加手順

僕みたいな初心者が陥りがちなのが、以下のようにして追加できた気になるという。

import anorm._

けれども、これで実行すると

not found: object anorm

ってエラーが。
これは、build.sbt に以下を追記することで解決できた。

build.sbt
libraryDependencies ++= Seq(
  jdbc,
  "com.typesafe.play" %% "anorm" % "2.5.1"
)

ただし、追記して

$ sbt compile

再度コンパイルする必要あり。
これで無事 Anorm を追加できました。

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5