Scala helpers for JDBI
Scala Java
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore initial commit Apr 23, 2012
LICENSE initial commit Apr 23, 2012 Expanded README Apr 7, 2013 Upgrade versions, add scala 2.11, drop 2.9 Dec 30, 2014
version.sbt Setting version to 0.3.1-SNAPSHOT Dec 30, 2014


Some handy classes for making JDBI even nicer to use with Scala

Currently it allows you to:

  • Bind case classes in SQL statements
  • Bind simple scala.Option types to SQL statement arguments
  • Return Options from SQL queries
  • Use function literal syntax when running code in a DB transaction


Binding Case Classes

import com.gilt.jdbi.BindCaseClass

  insert into doo_hickeys (id, label, widget_id)
  values (, :dh.label, :dh.widgetId)
def insert(@BindCaseClass("dh") dooHickey: DooHickey

Binding Option types

In application setup code:

import com.gilt.jdbi.args.OptionArgumentFactory

In your DAO:

  insert into widgets (label, description)
  values (:label, :desc)
def insert(@Bind("label") label: String, @Bind("desc") desc: Option[String])

Note that since ArgumentFactories are not recursive, your Option must contain a type which is directly compatible with JDBC.

Returning Options from queries

In application setup code:

import com.gilt.jdbi.OptionContainerFactory
db.registerContainerFactory(new OptionContainerFactory)

In your DAO:

@SqlQuery("select * from doo_hickeys where key = :key")
def findByKey(@Bind("key") key: String): Option[DooHickey]

Using function literals

import com.gilt.jdbi.Conversions._

  (h: Handle, status: TransactionStatus) => {
    // transactional code