Setup
ScalikeJDBC libraries are available on the Maven central repository.
https://search.maven.org/search?q=org.scalikejdbc
Core Library & Interpolation
To get started with ScalikeJDBC, add the latest version of the core library along with the necessary JDBC driver and an SLF4J implementation to your project’s build configuration. Here’s how you can do this in your build.sbt
file:
libraryDependencies ++= Seq(
"org.scalikejdbc" %% "scalikejdbc" % "4.3.2",
"com.h2database" % "h2" % "2.2.224",
"ch.qos.logback" % "logback-classic" % "1.5.6"
)
In your app code, add the following line of code to import the module:
import scalikejdbc._
Testing Support
Using scalikejdbc-test
is highly recommended to improve your application.
libraryDependencies ++= Seq(
"org.scalikejdbc" %% "scalikejdbc" % "4.3.2",
"org.scalikejdbc" %% "scalikejdbc-test" % "4.3.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" % "4.3.2",
"org.scalikejdbc" %% "scalikejdbc-config" % "4.3.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" % "4.3.2")
build.sbt
enablePlugins(ScalikejdbcPlugin)
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 java.time.LocalDateTime)
generator.dateTimeClass=java.time.ZonedDateTime
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 https://git.io/dbcon | sh
Windows
https://git.io/dbcon.bat
Usage: /documentation/dbconsole