Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scalikejdbc/scalikejdbc-play-support
Play Framework support
https://github.com/scalikejdbc/scalikejdbc-play-support
playframework scala scalikejdbc
Last synced: 5 days ago
JSON representation
Play Framework support
- Host: GitHub
- URL: https://github.com/scalikejdbc/scalikejdbc-play-support
- Owner: scalikejdbc
- License: other
- Created: 2014-03-06T04:14:20.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-12-24T01:41:47.000Z (5 days ago)
- Last Synced: 2024-12-24T02:35:29.323Z (5 days ago)
- Topics: playframework, scala, scalikejdbc
- Language: Scala
- Homepage: https://scalikejdbc.org/documentation/playframework-support.html
- Size: 427 KB
- Stars: 55
- Watchers: 14
- Forks: 23
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# ScalikeJDBC Play Support
This is a project to enable using ScalikeJDBC in Play Framework apps seamlessly.
https://scalikejdbc.org/
### Getting Started with Play 3.0
#### build.sbt
```scala
libraryDependencies ++= Seq(
"com.h2database" % "h2" % "2.2.224", // your jdbc driver here
"org.scalikejdbc" %% "scalikejdbc" % "4.3.0",
"org.scalikejdbc" %% "scalikejdbc-config" % "4.3.0",
"org.scalikejdbc" %% "scalikejdbc-play-initializer" % "3.0.0-scalikejdbc-4.3"
)
```#### conf/application.conf
```
# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play;DB_CLOSE_DELAY=-1"
# NOTE: sclaikejdbc-config 2.2.6 doesn't support username, use 2.2.7 or higher
db.default.username=sa
db.default.password=sa# ScalikeJDBC original configuration
#db.default.poolInitialSize=10
#db.default.poolMaxSize=10
#db.default.poolValidationQuery=scalikejdbc.global.loggingSQLErrors=true
scalikejdbc.global.loggingSQLAndTime.enabled=true
scalikejdbc.global.loggingSQLAndTime.singleLineMode=false
scalikejdbc.global.loggingSQLAndTime.logLevel=debug
scalikejdbc.global.loggingSQLAndTime.warningEnabled=true
scalikejdbc.global.loggingSQLAndTime.warningThresholdMillis=5
scalikejdbc.global.loggingSQLAndTime.warningLogLevel=warnplay.modules.enabled += "scalikejdbc.PlayModule"
```#### app/controllers/Application.scala
Now you can access ScalikeJDBC everywhere in your Play app!
```scala
package controllersimport javax.inject._
import play.api._
import play.api.mvc._
import scalikejdbc._@Singleton
class Application @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
implicit val session: DBSession = AutoSessiondef index = Action {
val accounts = {
try sql"select * from accounts".toMap.list.apply()
catch { case e: Exception =>
sql"create table accounts(name varchar(100) not null)".execute.apply()
Seq("Alice", "Bob", "Chris").foreach { name =>
sql"insert into accounts values ($name)".update.apply()
}
sql"select * from accounts".toMap.list.apply()
}
}
Ok(accounts.toString)
}
}
```### Migration Guide
Unfortunately, Play 2.4 is basically incompatible with Play plugins.
Since Play 2.4, you need to switch to use Play modules instead.#### ScalikeJDBC integration with Play 2.0 - 2.3
- scalikejdbc-play-plugin
- scalikejdbc-play-dbplugin-adapter
- scalikejdbc-play-fixture-plugin#### ScalikeJDBC integration with Play 2.4 or higher
- scalikejdbc-play-initializer
- scalikejdbc-play-dbapi-adapter
- scalikejdbc-play-fixture## License
```
Copyright ScalikeJDBC committers
Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0.html
```