playとSquerylの設定
playとSquerylを使う機会があったのでメモ。
ちなみにplayはplay2.3です。
play側のDBアクセス設定
ScalaDatabase
my_project/conf/application.confに↓の設定を行う
# Database configuration db.default.driver=org.postgresql.Driver db.default.url="jdbc:postgresql://ip_address/db_name" db.default.user=user_name db.default.password=pass_word
今回はORMにSquerylを使います。
Introduction - Squeryl - A Scala ORM for SQL Databases
ではこのページを参考に作業を進めていきます。
Getting Started - Squeryl - A Scala ORM for SQL Databases
sbtファイルの設定。
今回はDBはpostgreSQL、ORMにSquerylを使用するので、それぞれをSBTファイルに書き込みます。
built.sbtと書かれたファイルに↓のように記述
libraryDependencies ++= Seq( jdbc, "org.squeryl" %% "squeryl" % "0.9.5-7", "postgresql" % "postgresql" % "9.1-901.jdbc4" )
ちなみに上の各ライブラリのバージョンは、squerylの場合「squeryl sbt」みたいにググればでてきました。
Maven Repository: org.squeryl » squeryl_2.10 » 0.9.5-6
compileコマンドでerrorが出なかったらひとまずOK
[my-project] $ compile
*私はjdbcの記述を抜かしていたことでerrorが出ていました。
JDBCって今回初めて知り。。。(汗)
JDBC - Wikipedia
次の記事ではスキーマの定義をしていきます。
参考ページ
https://www.playframework.com/documentation/ja/2.2.x/NewApplication