16. Extensions for H2

In this chapter we discuss the extended support that doobie offers for users of H2 . To use these extensions you must add an additional dependency to your project:

libraryDependencies += "org.tpolecat" %% "doobie-h2" % doobieVersion

This library pulls in H2 Version 1.3.170 as a transitive dependency.

Array Types

doobie supports H2 arrays of the following types:

In addition to Array you can also map to List and Vector.

See the previous chapter on SQL Arrays for usage examples.

Other Nonstandard Types

H2 Connection Pool

doobie provides a Transactor that wraps the connection pool provided by H2. Because the transactor has internal state, constructing one is a side-effect that must be captured (here by Task).

import doobie.imports._
import doobie.h2.imports._

import fs2.interop.cats._

val q = sql"select 42".query[Int].unique

for {
  xa <- H2Transactor[IOLite]("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "")
  _  <- xa.setMaxConnections(10) // and other ops; see scaladoc or source
  a  <- q.transact(xa)
} yield a