Skip to content
/ doobie Public
forked from typelevel/doobie

principled database access for scala

License

Notifications You must be signed in to change notification settings

ronanM/doobie

 
 

Repository files navigation

doobie

Travis CI Join the chat at https://gitter.im/tpolecat/doobie Maven Central

doobie is a pure functional JDBC layer for Scala. It is not an ORM, nor is it a relational algebra; it just provides a principled way to construct programs (and higher-level libraries) that use JDBC. doobie introduces very few new abstractions; if you are familiar with basic scalaz typeclasses like Functor and Monad you should have no trouble here.

For common use cases doobie provides a minimal but expressive high-level API:

import doobie.imports._, scalaz.effect.IO

val xa = DriverManagerTransactor[IO](
  "org.postgresql.Driver", "jdbc:postgresql:world", "postgres", ""
)

case class Country(code: String, name: String, population: Long)

def find(n: String): ConnectionIO[Option[Country]] = 
  sql"select code, name, population from country where name = $n".query[Country].option

// And then

scala> find("France").transact(xa).unsafePerformIO
res0: Option[Country] = Some(Country(FRA,France,59225700))

doobie is a Typelevel project. This means we embrace pure, typeful, functional programming, and provide a safe and friendly environment for teaching, learning, and contributing as described in the Typelevel Code of Conduct.

Quick Start

Supported releases and dependencies are shown below.

doobie status jdk scala scalaz scalaz-stream shapeless
0.3.0 stable 1.8+ 2.10, 2.11, 2.12 7.2 0.8 2.3
0.2.4 stable 1.7+ 2.10, 2.11 7.1 0.8 2.2
0.2.3 eol 1.6+ 2.10, 2.11 7.1 0.7 2.2

Note that doobie is pre-1.0 software and is still undergoing active development. New versions are not binary compatible with prior versions, although in most cases user code will be source compatible. Nontrivial breaking changes will be introduced through a deprecation cycle of at least one minor (0.x) release.

To use doobie you need to add the following to your build.sbt.

libraryDependencies += "org.tpolecat" %% "doobie-core" % "0.3.0" // or any supported release above

If you are using Scala 2.10 you must also add the paradise compiler plugin.

addCompilerPlugin("org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full)

It is likely that you will want one or more add-on libraries. doobie provides the following, which have the same version as doobie-core and are released together.

  • doobie-contrib-h2 for H2-specific type mappings.
  • doobie-contrib-hikari for HikariCP connection pooling.
  • doobie-contrib-postgresql for PostgreSQL-specific type mappings.
  • doobie-contrib-specs2 for specs2 support for typechecking queries.

See the book of doobie for more information on these add-ons.

Documentation and Support

  • See the changelog for an overview of changes in this and previous versions.
  • Behold the book of doobie ← start here
  • The scaladoc will be handy once you get your feet wet.
  • There is also the source. If you're here you know where to look. Check the examples.
  • If you have comments or run into trouble, please file an issue.
  • Find tpolecat on the FreeNode #scala channel, or join the Gitter Channel.

Presentations, Blog Posts, etc.

Listed newest first. If you have given a presentation or have written a blog post that includes doobie, let me know and I'll add it to this list.

About

principled database access for scala

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 97.5%
  • Shell 2.5%