A tidy SQL-based DB access library for Scala developers. This library naturally wraps JDBC APIs and provides you easy-to-use APIs.
Scala Shell Batchfile
Pull request Compare This branch is 244 commits behind scalikejdbc:master.
Permalink
Failed to load latest commit information.
notes version 2.2.9 Oct 11, 2015
project Bump slf4j-api, joda-time minor version Nov 11, 2015
sandbox 2.2.9 Oct 12, 2015
scalikejdbc-cli Bump scala 2.10 to 2.10.6, bump minor test deps Oct 10, 2015
scalikejdbc-config Configurable warm up time for new connection pools Aug 26, 2015
scalikejdbc-core add support of java.time.Instant parameters Oct 16, 2015
scalikejdbc-interpolation-macro Remove copyright from source code Mar 18, 2015
scalikejdbc-interpolation Bump minor deps, fix test stability Oct 13, 2015
scalikejdbc-jsr310 add support of java.time.Instant parameters Oct 16, 2015
scalikejdbc-library Remove copyright from source code Mar 18, 2015
scalikejdbc-mapper-generator-core remove trailing space Oct 13, 2015
scalikejdbc-mapper-generator Bump scala 2.10 to 2.10.6, bump minor test deps Oct 10, 2015
scalikejdbc-syntax-support-macro renamed Jun 1, 2015
scalikejdbc-test Remove copyright from source code Mar 18, 2015
scripts Bump scala 2.10 to 2.10.6, bump minor test deps Oct 10, 2015
tools-support/intellij/templates scalikejdbc.SQLInterpolation is deprecated Dec 31, 2014
.gitignore Added templates for Intellij IDEA Jul 8, 2013
.travis.yml Bump scala 2.10 to 2.10.6, bump minor test deps Oct 10, 2015
CONTRIBUTING.md Update MiMa policy since 2.3.x series Oct 13, 2015
LICENSE.txt Update copyright Feb 28, 2015
logo.png Updated logo Jun 16, 2014
readme.md Corrected the language marker for code block in readme.md Oct 26, 2015
team-rules.md version 2.2.4 Feb 28, 2015
travis.sh Bump scala 2.10 to 2.10.6, bump minor test deps Oct 10, 2015
travis_before.sh should not execute "git add" multiple times Mar 20, 2015

readme.md

ScalikeJDBC

Just write SQL and get things done!

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

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

http://scalikejdbc.org/

Build Status

Gitter Chat for Casual Q&A

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

Getting Started

All you need to do is just adding ScalikeJDBC, JDBC driver & slf4j implementation.

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

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

https://github.com/scalikejdbc/scalikejdbc-play-support

First example

Put above dependencies into your build.sbt and run sbt console now.

//import scalikejdbc._, SQLInterpolation._
import scalikejdbc._

// initialize JDBC driver & connection pool
Class.forName("org.h2.Driver")
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
sql"""
create table members (
  id serial not null primary key,
  name varchar(64),
  created_at timestamp not null
)
""".execute.apply()

// 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 org.joda.time._
case class Member(id: Long, name: Option[String], createdAt: DateTime)
object Member extends SQLSyntaxSupport[Member] {
  override val tableName = "members"
  def apply(rs: WrappedResultSet): Member = new Member(
    rs.long("id"), rs.stringOpt("name"), rs.jodaDateTime("created_at"))
}

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

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

http://scalikejdbc.org/

License

Published source code and binary files have the following copyright:

Copyright scalikejdbc.org
Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0.html