Play Framework Support
For ScalikeJDBC 3.0 or higher, support is provided exclusively for Play Framework version 2.6 or higher.
- scalikejdbc-play-initializer
- scalikejdbc-play-dbapi-adapter
- scalikejdbc-play-fixture
scalikejdbc-play-initializer
This module also includes support for connection pooling.
build.sbt
libraryDependencies ++= Seq(
"com.h2database" % "h2" % "2.2.224", // your jdbc driver here
"org.scalikejdbc" %% "scalikejdbc" % "4.3.2",
"org.scalikejdbc" %% "scalikejdbc-config" % "4.3.2",
"org.scalikejdbc" %% "scalikejdbc-play-initializer" % "3.0.0-scalikejdbc-4.2"
)
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"
db.default.username=sa
db.default.password=sa
# ScalikeJDBC original configuration
#db.default.poolInitialSize=10
#db.default.poolMaxSize=10
#db.default.poolValidationQuery=
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"
# scalikejdbc.PlayModule doesn't depend on Play's DBModule
play.modules.disabled += "play.api.db.DBModule"
scalikejdbc-dbapi-adapter
build.sbt
libraryDependencies ++= Seq(
"com.h2database" % "h2" % "2.2.224", // your jdbc driver here
"org.scalikejdbc" %% "scalikejdbc" % "4.3.2",
"org.scalikejdbc" %% "scalikejdbc-config" % "4.3.2",
"org.scalikejdbc" %% "scalikejdbc-play-dbapi-adapter" % "3.0.0-scalikejdbc-4.2"
)
conf/application.conf
This plugin is an adapter to connect play.api.db.DBApi
and ScalikeJDBC.
# others are same as Play's defaults
play.modules.enabled += "scalikejdbc.PlayDBApiAdapterModule"
Fixtures - scalikejdbc-play-fixture
db.default.fixtures.test=["users.sql", "project.sql", "project_member.sql", "task.sql"]
#db.secondary.fixtures.test=["users.sql", "project.sql", "project_member.sql", "task.sql"]
play.modules.enabled += "scalikejdbc.PlayFixtureModule"
conf/db/fixtures/default/project.sql
# --- !Ups
INSERT INTO project (id, name, folder) VALUES (1, 'Play 2.0', 'Play framework');
INSERT INTO project (id, name, folder) VALUES (2, 'Play 1.2.4', 'Play framework');
INSERT INTO project (id, name, folder) VALUES (3, 'Website', 'Play framework');
INSERT INTO project (id, name, folder) VALUES (4, 'Secret project', 'Zenexity');
INSERT INTO project (id, name, folder) VALUES (5, 'Playmate', 'Zenexity');
INSERT INTO project (id, name, folder) VALUES (6, 'Things to do', 'Personal');
INSERT INTO project (id, name, folder) VALUES (7, 'Play samples', 'Zenexity');
INSERT INTO project (id, name, folder) VALUES (8, 'Private', 'Personal');
INSERT INTO project (id, name, folder) VALUES (9, 'Private', 'Personal');
INSERT INTO project (id, name, folder) VALUES (10, 'Private', 'Personal');
INSERT INTO project (id, name, folder) VALUES (11, 'Private', 'Personal');
ALTER SEQUENCE project_seq RESTART WITH 12;
# --- !Downs
ALTER SEQUENCE project_seq RESTART WITH 1;
DELETE FROM project;
conf/db/fixtures/defaut/project_member.sql
# --- !Ups
INSERT INTO project_member (project_id, user_email) VALUES (1, 'guillaume@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (1, 'maxime@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (1, 'sadek@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (1, 'erwan@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (2, 'guillaume@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (2, 'erwan@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (3, 'guillaume@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (3, 'maxime@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (4, 'guillaume@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (4, 'maxime@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (4, 'sadek@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (4, 'erwan@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (5, 'maxime@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (6, 'guillaume@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (7, 'guillaume@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (7, 'maxime@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (8, 'maxime@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (9, 'guillaume@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (10, 'erwan@sample.com');
INSERT INTO project_member (project_id, user_email) VALUES (11, 'sadek@sample.com');
# --- !Downs
DELETE FROM project_member;
If this webpage has a typo or something wrong, Please report or fix it. How?