Skip to content
This repository

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

Merge pull request #228 from tkawachi/setup-sh

Changed to refer $HOME instead of $HOME_DIR
latest commit 77898872aa
Kazuhiro Sera seratch authored April 23, 2014
Octocat-spinner-32 notes Added release notes April 23, 2014
Octocat-spinner-32 project version 2.0.0-beta2 April 22, 2014
Octocat-spinner-32 sandbox version 2.0.0-beta2 April 22, 2014
Octocat-spinner-32 scalikejdbc-cli Changed to refer $HOME instead of $HOME_DIR April 23, 2014
Octocat-spinner-32 scalikejdbc-config Started version 2.0 development March 06, 2014
Octocat-spinner-32 scalikejdbc-core Get an old pool in a synchronized block April 23, 2014
Octocat-spinner-32 scalikejdbc-interpolation-core Fixed #216 Interpolation support for Traversable[SQLSyntax] April 22, 2014
Octocat-spinner-32 scalikejdbc-interpolation-macro To be compatible with Scala 2.11 refs #206 March 04, 2014
Octocat-spinner-32 scalikejdbc-interpolation ScalikeJDBC 2.0.x phase implementation for #222 WrappedResultSet#date… April 22, 2014
Octocat-spinner-32 scalikejdbc-library Modules structure improvement April 22, 2014
Octocat-spinner-32 scalikejdbc-mapper-generator-core Fixed #219 [mapper-generator] Generating case class for 22+ columns t… April 22, 2014
Octocat-spinner-32 scalikejdbc-mapper-generator Fixed #219 [mapper-generator] Generating case class for 22+ columns t… April 22, 2014
Octocat-spinner-32 scalikejdbc-test Modules structure improvement April 22, 2014
Octocat-spinner-32 scripts version 2.0.0-beta2 April 22, 2014
Octocat-spinner-32 tools-support version 1.7.0 November 20, 2013
Octocat-spinner-32 .gitignore Added templates for Intellij IDEA July 08, 2013
Octocat-spinner-32 .travis.yml Scala 2.11.0 final April 20, 2014
Octocat-spinner-32 CONTRIBUTING.md Added contributing guidelines (thanks to @xuwei-k December 28, 2013
Octocat-spinner-32 LICENSE.txt Added license for released binary files June 10, 2013
Octocat-spinner-32 logo.png Added logo April 06, 2013
Octocat-spinner-32 readme.md version 2.0.0-beta2 April 22, 2014
Octocat-spinner-32 team-rules.md Renamed rules for team December 29, 2013
Octocat-spinner-32 travis.sh travis settings for Scala2.11 March 09, 2014
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/

Getting Started

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

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

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) = new Member(
    rs.long("id"), rs.stringOpt("name"), rs.dateTime("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 binary files have the following copyright:

Copyright 2013 ScalikeJDBC committers
Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0.html
Something went wrong with that request. Please try again.