WARNING: This page is a guide for 1.x series.

Setup


ScalikeJDBC libraries are available on the Maven central repository.

https://search.maven.org/search?q=org.scalikejdbc


Core Library & Interpolation


Add latest version into your build.sbt or project/Build.scala. Don’t forget JDBC driver and slf4j implementation.

If you’re still using Scala 2.9, you can’t use scalikejdbc-interpolation.

libraryDependencies ++= Seq(
  "org.scalikejdbc" %% "scalikejdbc"               % "1.7.7",
  "org.scalikejdbc" %% "scalikejdbc-interpolation" % "1.7.7",
  "com.h2database"  %  "h2"                        % "1.4.177",
  "ch.qos.logback"  %  "logback-classic"           % "1.1.2"
)

In your application, just add the following import.

import scalikejdbc._, SQLInterpolation._

Testing Support


Using scalikejdbc-test is highly recommended to improve your application.

libraryDependencies ++= Seq(
  "org.scalikejdbc" %% "scalikejdbc"               % "1.7.7",
  "org.scalikejdbc" %% "scalikejdbc-interpolation" % "1.7.7",
  "org.scalikejdbc" %% "scalikejdbc-test"          % "1.7.7"   % "test",
  "com.h2database"  %  "h2"                        % "1.4.177",
  "ch.qos.logback"  %  "logback-classic"           % "1.1.2"
)

Usage: /documentation/testing


Typesafe Config Reader


If you use application.conf as settings file, add scalikejdbc-config too.

libraryDependencies ++= Seq(
  "org.scalikejdbc" %% "scalikejdbc"               % "1.7.7",
  "org.scalikejdbc" %% "scalikejdbc-interpolation" % "1.7.7",
  "org.scalikejdbc" %% "scalikejdbc-config"        % "1.7.7",
  "com.h2database"  %  "h2"                        % "1.4.177",
  "ch.qos.logback"  %  "logback-classic"           % "1.1.2"
)

Usage: /documentation/configuration


Reverse Engineering


ScalikeJDBC support reverse engineering Scala code from existing database. You need to setup an sbt plugin named scalikejdbc-mapper-generator.

project/plugins.sbt
// Don't forget adding your JDBC driver
libraryDependencies += "org.hsqldb" % "hsqldb" % "2.3.2"

addSbtPlugin("org.scalikejdbc" %% "scalikejdbc-mapper-generator" % "1.7.7")
build.sbt
scalikejdbcSettings
project/scalikejdbc.properties
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:file:./db/hello
jdbc.username=sa
jdbc.password=
jdbc.schema=
generator.packageName=models
# generator.lineBreak: LF/CRLF
generator.lineBreak=LF
# generator.template: basic/namedParameters/executable/interpolation/queryDsl
generator.template=queryDsl
# generator.testTemplate: specs2unit/specs2acceptance/ScalaTestFlatSpec
generator.testTemplate=specs2unit
generator.encoding=UTF-8

Usage: /documentation/reverse-engineering


Play Framework Integration


Add scalikejdbc-play-plugin and scalikejdbc-play-fixture-plugin (optional) as Play plugins.

project/Build.scala
val appDependencies = Seq(
  "org.scalikejdbc" %% "scalikejdbc"                     % "1.7.7",
  "org.scalikejdbc" %% "scalikejdbc-play-plugin"         % "1.7.7",
  "org.scalikejdbc" %% "scalikejdbc-play-fixture-plugin" % "1.7.7", // optional
  // substitute this for whatever DB driver you're using:
  "com.h2database"  %  "h2"                              % "1.4.177"
)
conf/play.plugins
10000:scalikejdbc.PlayPlugin

If you use fixture-plugin too, PlayFixturePlugin should be loaded after PlayPlugin:

10000:scalikejdbc.PlayPlugin
11000:scalikejdbc.PlayFixturePlugin

Usage: /documentation/playframework-support


dbconsole


A simple console to connect database via JDBC.

Mac OS X, Linux
curl -L http://git.io/dbcon | sh
Windows
http://git.io/dbcon.bat

Usage: /documentation/dbconsole


If this webpage has a typo or something wrong, Please report or fix it. How?