Created
April 27, 2012 03:09
-
-
Save seratch/2505361 to your computer and use it in GitHub Desktop.
ScalikeJDBC Play20 plugin prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package controllers | |
| import play.api._ | |
| import play.api.mvc._ | |
| import scalikejdbc._ | |
| object Application extends Controller { | |
| def index = Action { | |
| val userIdList: List[Int] = DB readOnly { implicit session => | |
| SQL("select id from user").map(rs => rs.int("id")).toList.apply() | |
| } | |
| // TODO NamedDB('ds1) readOnly { ... } | |
| Ok(views.html.index("Your new application is ready.")) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 777:scalikejdbc.play20.ScalikeJDBCPlugin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package scalikejdbc.play20 | |
| import play.api._ | |
| import play.api.db.BoneCPPlugin | |
| import java.sql.Connection | |
| import scalikejdbc._ | |
| class ScalikeJDBCPlugin(app: Application) extends BoneCPPlugin(app) { | |
| override def onStart() {} | |
| private lazy val config = app.configuration.getConfig("db").getOrElse(Configuration.empty) | |
| private def getConfigValue(config: Configuration, name: String, key: String): String = config.getString(name + "." + key) getOrElse { | |
| throw config.reportError(name, "Missing configuration [db." + name + "." + key + "]") | |
| } | |
| config.subKeys map { name => | |
| val url = getConfigValue(config, name, "url") | |
| val user = getConfigValue(config, name, "user") | |
| val password = getConfigValue(config, name, "password") | |
| name match { | |
| case "default" => ConnectionPool.singleton(url, user, password) | |
| case _ => ConnectionPool.add(Symbol(name), url, user, password) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment