GithubHelp home page GithubHelp logo

doobie's Introduction

doobie

[![Travis CI](https://travis-ci.org/tpolecat/doobie.svg?branch=series%2F0.4.x)](https://travis-ci.org/tpolecat/doobie) [![Join the chat at https://gitter.im/tpolecat/doobie](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tpolecat/doobie?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Maven Central](https://img.shields.io/maven-central/v/org.tpolecat/doobie-core_2.12.svg)](https://maven-badges.herokuapp.com/maven-central/org.tpolecat/doobie-core_2.12)

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 core 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

Recent releases and dependencies are shown below. The current release is 0.4.1 … if you wish to use an older version please switch to the associated tag. The remainder of this document assumes you're using the current release.

doobie status jdk scala scalaz scalaz-stream cats fs2 shapeless
0.4.1 current 1.8+ 2.10, 2.11, 2.12 7.2 0.8 0.9 0.9 2.3
0.4.0 current 1.8+ 2.10, 2.11, 2.12 7.2 0.8 0.8 0.9 2.3
0.3.0 eol 1.8+ 2.10, 2.11, 2.12 7.2 0.8 -- -- 2.3
0.2.4 eol 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

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

libraryDependencies += "org.tpolecat" %% "doobie-core"      % "0.4.1" // scalaz + scalaz-stream
                       "org.tpolecat" %% "doobie-core-cats" % "0.4.1" // cats   + fs2

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

addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" 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[-cats] and are released together.

scalaz cats description
doobie-h2 doobie-h2-cats H2-specific type mappings.
doobie-hikari doobie-hikari-cats HikariCP connection pooling.
doobie-postgres doobie-postgres-cats PostgreSQL-specific type mappings.
doobie-specs2 doobie-specs2-cats specs2 support for typechecking queries.
doobie-scalatest doobie-scalatest-cats ScalaTest support for typechecking queries.

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

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.

Development Version

The active development version is 0.4.2-SNAPSHOT. It is updated sporadically and is subject to unannounced changes. See the changelog for information on work in progress.

Documentation and Support

  • See the changelog for an overview of changes in this and previous versions.
  • Behold the book of doobie for scalaz and cats ← start here
  • There is a Scala Exercises module, courtesy of our friends at 47 Degrees!
  • 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.

Testing

If you want to build and run the tests for yourself, you'll need a local postgresql database. Tests are run as the default postgres user, which should have no password for access in the local environment. You can see the before_script section of the .travis.yml file for an up-to-date list of steps for preparing the test database.

doobie's People

Contributors

alexadewit avatar ant8e avatar aryairani avatar channingwalton avatar coltfred avatar etorreborre avatar fiadliel avatar fthomas avatar gatorcse avatar gseitz avatar guersam avatar heliocentrist avatar ikhoon avatar j-keck avatar kadekm avatar kryptt avatar leifwickland avatar mdmoss avatar milessabin avatar milyardo avatar n4to4 avatar pepegar avatar peterneyens avatar raulraja avatar ritschwumm avatar ronanm avatar sritchie avatar tpolecat avatar veegee avatar wedens avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.