scalikejdbc-config ã¢ã¸ã¥ã¼ã«ãä½ãã¾ãã
scalikejdbc 使ãã¨ãã«ãè¨å®ãã¡ã¤ã«èªãã ãããã®ãããã©ããããªã£ãã®ã§ãtypesafe-config ã使ã£ã¦ application.conf ãèªãå¦çãã¾ã¨ãã¾ããã
https://github.com/tototoshi/scalikejdbc-config
(ä¸ç¥)
scalikejdbc æ¬ä½ã«å
¥ãã¦ãããã¾ããã
https://github.com/seratch/scalikejdbc/tree/develop/scalikejdbc-config
ã¤ã³ã¹ãã¼ã«
libraryDependencies ++= Seq( "com.github.seratch" %% "scalikejdbc" % "[1.4,)", "com.github.seratch" %% "scalikejdbc-config" % "[1.4,)" )
使ãæ¹
src/main/resources/application.conf ã«è¨å®ãæ¸ãã¾ãã
db.default.url="jdbc:h2:mem:sample1" db.default.driver="org.h2.Driver" db.default.user="sa" db.default.password="secret"
db.foo.url ã¨ããè¨å®ãªã DBs.setup('foo) ã§ã³ãã¯ã·ã§ã³ãã¼ã«ãã»ããã¢ããããã¾ãã
db.default.url ã¯ç¹å¥(Play ã¿ããã«)æ±ãã§ãDBs.setup() 㧠OKã
ãã¼ã¿ãã¼ã¹ãè¤æ°ä½¿ãã¨ã㯠DBs.setupAll ã§ä¸æ°ã«ãã¼ã«ãæºåã§ãã¾ãã
ãã¨ãseraããããããã追å ãã¦ãããã®ã§ãã°ã¨ããã¼ã«ã®ç´°ããè¨å®ãã§ãã¾ããã
package org.example import scalikejdbc._ import scalikejdbc.config._ object Main extends App { DBs.setup() DB readOnly { implicit session => val one = SQL("SELECT 1 AS one").map(rs => rs.int("one")).single.apply() println(one) } DBs.close() }