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" % "2.5.2",
"com.h2database" % "h2" % "2.2.224",
"ch.qos.logback" % "logback-classic" % "1.5.6"
)
In your application, just add the following import.
import scalikejdbc._
Testing Support
Using scalikejdbc-test
is highly recommended to improve your application.
libraryDependencies ++= Seq(
"org.scalikejdbc" %% "scalikejdbc" % "2.5.2",
"org.scalikejdbc" %% "scalikejdbc-test" % "2.5.2" % "test",
"com.h2database" % "h2" % "2.2.224",
"ch.qos.logback" % "logback-classic" % "1.5.6"
)
Usage: /documentation/testing
Typesafe Config Reader
If you use application.conf
as settings file, add scalikejdbc-config
too.
libraryDependencies ++= Seq(
"org.scalikejdbc" %% "scalikejdbc" % "2.5.2",
"org.scalikejdbc" %% "scalikejdbc-config" % "2.5.2",
"com.h2database" % "h2" % "2.2.224",
"ch.qos.logback" % "logback-classic" % "1.5.6"
)
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" % "2.5.2")
build.sbt
scalikejdbcSettings
project/scalikejdbc.properties
# ---
# jdbc settings
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:file:./db/hello
jdbc.username=sa
jdbc.password=
jdbc.schema=
# ---
# source code generator settings
generator.packageName=models
# generator.lineBreak: LF/CRLF
generator.lineBreak=LF
# generator.template: interpolation/queryDsl
generator.template=queryDsl
# generator.testTemplate: specs2unit/specs2acceptance/ScalaTestFlatSpec
generator.testTemplate=specs2unit
generator.encoding=UTF-8
# When you're using Scala 2.11 or higher, you can use case classes for 22+ columns tables
generator.caseClassOnly=true
# Set AutoSession for implicit DBSession parameter's default value
generator.defaultAutoSession=true
# Use autoConstruct macro (default: false)
generator.autoConstruct=false
# joda-time (org.joda.time.DateTime) or JSR-310 (java.time.ZonedDateTime java.time.OffsetDateTime)
generator.dateTimeClass=org.joda.time.DateTime
Usage: /documentation/reverse-engineering
Play Framework Integration
See in detail: /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