A tidy SQL-based DB access library for Scala developers. This library naturally wraps JDBC APIs and provides you easy-to-use APIs.
Pull request Compare This branch is 67 commits behind scalikejdbc:master.
Latest commit a7c6e09 Jun 23, 2018
Failed to load latest commit information.
notes Add 3.2.3 release note Mar 31, 2018
project use 'https' for SBT resolvers Jun 12, 2018
sandbox sbt 1.1.6 (scalikejdbc#892) Jun 2, 2018
scalikejdbc-cli sbt 1.1.6 (scalikejdbc#892) Jun 2, 2018
scalikejdbc-config Load default value instead of false if isn’t included in config Feb 15, 2018
scalikejdbc-core/src Merge pull request scalikejdbc#914 from xuwei-k/TypeBinder-of Jun 23, 2018
scalikejdbc-interpolation-macro/src/main/scala/scalikejdbc drop Scala 2.10 and sbt 0.13 support Jan 23, 2018
scalikejdbc-interpolation Scala 2.13.0-M4 Jun 16, 2018
scalikejdbc-joda-time/src TypeBinder timezone should be configurable Jun 22, 2018
scalikejdbc-library/src s/Traversable/Iterable/ May 28, 2018
scalikejdbc-mapper-generator-core add tableNameToSyntaxVariableName Jun 10, 2018
scalikejdbc-mapper-generator add tableNameToSyntaxVariableName Jun 10, 2018
scalikejdbc-streams Scala 2.13.0-M4 Jun 16, 2018
scalikejdbc-syntax-support-macro/src Scala 2.13.0-M4 May 27, 2018
scalikejdbc-test Bump sbt-scalariform version to the latest one Dec 6, 2017
scripts Scala 2.13.0-M4 Jun 16, 2018
tools-support/intellij/templates scalikejdbc.SQLInterpolation is deprecated Dec 31, 2014
.gitignore Ignore ensime related files Sep 22, 2016
.travis.yml update specs2. enable all tests for Scala 2.13.0-M4 Jun 18, 2018
CONTRIBUTING.md drop Scala 2.10 and sbt 0.13 support Jan 23, 2018
LICENSE.txt Update copyright Feb 28, 2015
build.sbt use specs2 4.3.0 for all scala versions Jun 22, 2018
logo.png Updated logo Jun 16, 2014
readme.md Update code examples on README Mar 10, 2018
team-rules.md remove sbt-pgp setting in team-rules.md Jan 19, 2018
travis.sh Scala 2.12.6 Apr 27, 2018
travis_before.sh should not execute "git add" multiple times Mar 20, 2015



Just write SQL and get things done!

ScalikeJDBC is a tidy SQL-based DB access library for Scala that naturally wraps JDBC and provides easy-to-use APIs.

ScalikeJDBC is practical and production-ready. Use this library for your real projects.


Build Status Maven Central

Gitter Chat for Casual Q&A

  • English: Gitter
  • 日本語 (Japanese): Gitter

Getting Started

Just add ScalikeJDBC, a JDBC driver, and an slf4j implementation to your sbt build settings:

libraryDependencies ++= Seq(
  "org.scalikejdbc" %% "scalikejdbc"        % "3.2.+",
  "com.h2database"  %  "h2"                 % "1.4.+",
  "ch.qos.logback"  %  "logback-classic"    % "1.2.+"

If you're a Play2 user, take a look at play-support project, too:


First example

After adding the above dependencies to your build.sbt, run sbt console and execute the following code:

import scalikejdbc._

// initialize JDBC driver & connection pool
ConnectionPool.singleton("jdbc:h2:mem:hello", "user", "pass")

// ad-hoc session provider on the REPL
implicit val session = AutoSession

// table creation, you can run DDL by using #execute as same as JDBC
create table members (
  id serial not null primary key,
  name varchar(64),
  created_at timestamp not null

// insert initial data
Seq("Alice", "Bob", "Chris") foreach { name =>
  sql"insert into members (name, created_at) values (${name}, current_timestamp)".update.apply()

// for now, retrieves all data as Map value
val entities: List[Map[String, Any]] = sql"select * from members".map(_.toMap).list.apply()

// defines entity object and extractor
import java.time._
case class Member(id: Long, name: Option[String], createdAt: ZonedDateTime)
object Member extends SQLSyntaxSupport[Member] {
  override val tableName = "members"
  def apply(rs: WrappedResultSet) = new Member(
    rs.long("id"), rs.stringOpt("name"), rs.zonedDateTime("created_at"))

// find all members
val members: List[Member] = sql"select * from members".map(rs => Member(rs)).list.apply()

// use paste mode (:paste) on the Scala REPL
val m = Member.syntax("m")
val name = "Alice"
val alice: Option[Member] = withSQL {
  select.from(Member as m).where.eq(m.name, name)
}.map(rs => Member(rs)).single.apply()

How did it go? If you'd like to know more details or see more practical examples, see the full documentation at:



Published source code and binary files have the following copyright:

Copyright scalikejdbc.org
Apache License, Version 2.0