12. Vendor Extensions
Version 0.2.0 introduces the doobie-contrib family of add-on libraries, which are published concurrently with the doobie release and provide support for functionality outside the JDBC specification. These can be added as needed:
libraryDependencies += "org.tpolecat" %% "doobie-contrib-XXX" % "0.2.0" // for some XXX
HikariCP Support
The doobie-contrib-hikari add-on provides a Transactor implementation backed by a HikariCP connection pool. Constructing an instance is an effect:
for {
xa <- HikariTransactor[Task]("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "")
_ <- longRunningProgram(xa) ensuring xa.shutdown
} yield ()
The returned instance is of type HikariTransactor, which provides a shutdown method (shown above) as well as a configure method that provides access to the underlying HikariDataSource. See the source for details.
H2 Support
The doobie-contrib-h2 add-on provides mappings for the following H2 types in the doobie.contrib.h2.h2types module.
- H2
arraytypes are supported and map toArray,List,Vector. - The
uuidtype is supported and maps tojava.util.UUID.
PostgreSQL Support
The doobie-contrib-postgres add-on provides mappings for the following PostgreSQL types in the doobie.contrib.postgresql.pgtypes module.
- Postgres typed arrays are supported and map to
Array,List,Vector. Multi-dimensional arrays are not supported yet. - The
uuidschema type is supported and maps tojava.util.UUID. - The
inetschema type is supported and maps tojava.net.InetAddress. - The following geometric types are supported, and map to driver-supplied types. These will normally be mapped to application-specific types.
- the
boxschema type maps toorg.postgresql.geometric.PGbox - the
circleschema type maps toorg.postgresql.geometric.PGcircle - the
lsegschema type maps toorg.postgresql.geometric.PGlseg - the
pathschema type maps toorg.postgresql.geometric.PGpath - the
pointschema type maps toorg.postgresql.geometric.PGpoint - the
polygonschema type maps toorg.postgresql.geometric.PGpolygon
- the
A complete table of SQLSTATE values is provided in the doobie.contrib.postgresql.sqlstate module, and recovery combinators for each of these (onUniqueViolation for example) are provided in doobie.contrib.postgresql.syntax.
Specs2 Support
The doobie-contrib-specs2 add-on provides a mix-in trait for Specs2 tests that provides support for query validation. See the chapter on unit testing for more information.