All Projects → scalikejdbc → scalikejdbc-play-support

scalikejdbc / scalikejdbc-play-support

Licence: other
Play Framework support

Programming Languages

scala
5932 projects
Less
1899 projects
coffeescript
4710 projects
HTML
75241 projects

Projects that are alternatives of or similar to scalikejdbc-play-support

scalikejdbc-bigquery
ScalikeJDBC extension for Google BigQuery
Stars: ✭ 18 (-67.27%)
Mutual labels:  scalikejdbc
sbt-play-npm
Integrate a Npm application with Play framework
Stars: ✭ 10 (-81.82%)
Mutual labels:  playframework
social-graph-api
Authentication & Social Graph API built on top of Redis, Neo4J and Play!
Stars: ✭ 13 (-76.36%)
Mutual labels:  playframework
IDEACodeTools
Intellij IDEA plugin for some code tools
Stars: ✭ 20 (-63.64%)
Mutual labels:  playframework
play-java-fileupload-example
An example Play application showing custom multiform fileupload in Java
Stars: ✭ 13 (-76.36%)
Mutual labels:  playframework
play-java-seed.g8
Play Java Seed template: use "sbt new playframework/play-java-seed.g8"
Stars: ✭ 20 (-63.64%)
Mutual labels:  playframework
sbt-sass
A fork of the sbt-sass repository which seems to be abandoned.
Stars: ✭ 32 (-41.82%)
Mutual labels:  playframework
play-scala-seed.g8
Play Scala Seed Template: run "sbt new playframework/play-scala-seed.g8"
Stars: ✭ 66 (+20%)
Mutual labels:  playframework
ddd-repository-example
ScalikeJDBC example for Domain Driven Design Repository implementation.
Stars: ✭ 24 (-56.36%)
Mutual labels:  scalikejdbc
play-scala-log4j2-example
An example Play project using Log4J 2 as the logging engine
Stars: ✭ 14 (-74.55%)
Mutual labels:  playframework
cachecontrol
Minimal HTTP cache management library in Scala
Stars: ✭ 13 (-76.36%)
Mutual labels:  playframework
play-scala-tls-example
A Play application using HTTPS and WS with optional client authentication
Stars: ✭ 44 (-20%)
Mutual labels:  playframework
play-json-extra
Play Json Extra extends Play Json with several opinionated features
Stars: ✭ 22 (-60%)
Mutual labels:  playframework
play-java-chatroom-example
Example Chatroom with Java API
Stars: ✭ 33 (-40%)
Mutual labels:  playframework
MuezzinAPI
A web server application for Islamic prayer times
Stars: ✭ 33 (-40%)
Mutual labels:  playframework
play-scala-compile-di-example
Example Play Project using compile time dependency injection and Play WS with ScalaTest
Stars: ✭ 37 (-32.73%)
Mutual labels:  playframework
subscriptions-frontend
sites.google.com/a/guardian.co.uk/guardian-subscriptions/
Stars: ✭ 15 (-72.73%)
Mutual labels:  playframework
play-java-rest-api-example
REST API using Play in Java
Stars: ✭ 44 (-20%)
Mutual labels:  playframework
play-grpc
Play + Akka gRPC
Stars: ✭ 31 (-43.64%)
Mutual labels:  playframework
hello-scalikejdbc
Lightbend Activator Template for ScalikeJDBC Beginners
Stars: ✭ 64 (+16.36%)
Mutual labels:  scalikejdbc

ScalikeJDBC Play Support

This is a project to enable using ScalikeJDBC in Play2 apps seamlessly.

http://scalikejdbc.org/

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

Getting Started with Play 2.8

build.sbt

libraryDependencies ++= Seq(
  "com.h2database"  %  "h2"                           % "1.4.200", // your jdbc driver here
  "org.scalikejdbc" %% "scalikejdbc"                  % "3.5.0",
  "org.scalikejdbc" %% "scalikejdbc-config"           % "3.5.0",
  "org.scalikejdbc" %% "scalikejdbc-play-initializer" % "2.8.0-scalikejdbc-3.5"
)

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=warn

play.modules.enabled += "scalikejdbc.PlayModule"

app/controllers/Application.scala

Now you can access ScalikeJDBC everywhere in your Play app!

package controllers

import javax.inject._
import play.api._
import play.api.mvc._
import scalikejdbc._

@Singleton
class Application @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
  implicit val session: DBSession = AutoSession

  def 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)
  }
}

License

Copyright ScalikeJDBC committers
Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0.html
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].