darco
The darco
package provides a minimalist, opinionated API for database access.
Features
- Versioned schema upgrades provided by trasco.
- Pluggable query support.
- Instrumented with OpenTelemetry.
- PostgreSQL support.
- SQLite support.
- Written in pure Java 17.
- OSGi ready
- JPMS ready
- ISC license
- High-coverage automated test suite
Motivation
Many io7m packages talk to various databases. For example:
- idstore uses PostgreSQL as the underlying persistent data store.
- cardant uses PostgreSQL as the underlying persistent data store.
- northpike uses PostgreSQL as the underlying persistent data store.
- certusine uses SQLite as the underlying persistent data store.
- looseleaf uses SQLite as the underlying persistent data store.
- ...
All of the listed projects abstracted the database behind a simplified set of interfaces to allow for easier unit testing, and to allow for migrating to different databases without having to completely rewrite all of the application code. This meant that each one of those projects had to implement its own set of nearly-identical interfaces and initialization code boilerplate.
In much the same manner as the
hibiscus API attempts to
provide a common interface around RPC clients, and the
anethum API attempts to
provide a common interface around parsers and serializers,
the darco
package attempts to provide a common set of interfaces and abstract
classes to minimize the amount of essentially duplicated code between projects
that talk to databases.
You probably don't want to use this package for your own applications. It is
intended to be used to keep io7m
packages consistent internally and to reduce
boilerplate.
Building
$ mvn clean verify
Usage
The com.io7m.darco.api
package provides the basic interfaces that abstract
over a relational database. Projects are expected to extend various provided
abstract classes, and implement various interfaces to provide their own
database abstractions. The package exposes a database as small set of core
types listed in the following sections.
DDatabaseFactoryType databases;
DDatabaseConfigurationType configuration;
try (DDatabaseType database = databases.open(configuration, () -> {})) {
try (DDatabaseConnectionType connection = database.openConnection()) {
try (DDatabaseTransactionType transaction = connection.openTransaction()) {
DDatabaseQueryType<String, DDatabaseUnit> query =
transaction.query(SomeCustomQueryType.class);
query.execute("Hello!");
query.execute("Goodbye!");
transaction.commit();
}
}
}
DDatabaseFactoryType
The DDatabaseFactoryType
interface represents objects that provide
database instances. When a DDatabaseFactoryType
is provided with a
DDatabaseConfigurationType value, it
yields a DDatabaseType instance.
DDatabaseConfigurationType
The DDatabaseConfigurationType
interface represents the basic configuration
properties required to open and/or connect to a database.
DDatabaseType
The DDatabaseType
interface represents an open database. To interact with
the database, callers must call the openConnection()
method to obtain a
DDatabaseConnectionType
instance. In a typical request/response server
application, the application would obtain a new connection for each incoming
client request, and close()
the connection after servicing the request.
DDatabaseConnectionType
The DDatabaseConnectionType
interface represents an open connection to
a database. In order to perform database queries using the connection,
applications must create transactions within
which to execute queries by calling the openTransaction()
method.
DDatabaseTransactionType
The DDatabaseTransactionType
interface represents a database transaction.
Applications perform work in transactions by requesting instances of
queries from the transaction. Transactions must be
explicitly committed, otherwise the work performed by queries inside the
transaction is implicitly rolled back.
DDatabaseQueryType
The DDatabaseQueryType
interface represents a single query that can be
executed within a transaction. A query typically abstracts over one or more
SQL statements. Queries are strongly typed and are represented as functions
taking parameters of type P
and returning results of type R
.
Query implementations are provided by instances of the
DDatabaseQueryProviderType
interface. Typically, a set of
DDatabaseQueryProviderType
instances are registered using ServiceLoader
.
SQLite
Applications wishing to provide an abstraction over the
SQLite database should extend the abstract classes
exposed by the com.io7m.darco.sqlite
module.
PostgreSQL
Applications wishing to provide an abstraction over the
PostgreSQL database should extend the abstract
classes exposed by the com.io7m.darco.postgres
module.
Examples
The com.io7m.darco.examples
module provides example implementations of
databases.
Releases & Development Snapshots
Releases
You can subscribe to the atom feed to be notified of project releases.
The most recently released version of the package is 3.1.0.
3.1.0 Release (2025-05-03Z)
- Update org.slf4j:slf4j-api:2.0.16 → 2.0.17.
- Update io.opentelemetry:opentelemetry-bom:1.48.0 → 1.49.0.
- Update org.junit:junit-bom:5.12.1 → 5.12.2.
- Update nl.jqno.equalsverifier:equalsverifier:3.19.2 → 3.19.4.
- Publish a com.io7m.darco.bom module.
The compiled artifacts for the release (and all previous releases) are available on Maven Central.
Maven Modules
<dependency> <group>com.io7m.darco</group> <artifactId>com.io7m.darco.api</artifactId> <version>3.1.0</version> </dependency><dependency> <group>com.io7m.darco</group> <artifactId>com.io7m.darco.bom</artifactId> <version>3.1.0</version> </dependency><dependency> <group>com.io7m.darco</group> <artifactId>com.io7m.darco.examples</artifactId> <version>3.1.0</version> </dependency><dependency> <group>com.io7m.darco</group> <artifactId>com.io7m.darco.postgres</artifactId> <version>3.1.0</version> </dependency><dependency> <group>com.io7m.darco</group> <artifactId>com.io7m.darco.sqlite</artifactId> <version>3.1.0</version> </dependency><dependency> <group>com.io7m.darco</group> <artifactId>com.io7m.darco.templating</artifactId> <version>3.1.0</version> </dependency><dependency> <group>com.io7m.darco</group> <artifactId>com.io7m.darco.tests</artifactId> <version>3.1.0</version> </dependency>
Previous Releases
The changelogs for the most recent previous releases are as follows:
3.0.0 Release (2025-04-15Z)
- Add the ability to register closeables on connections and transactions. (Tickets: 33)
- Update ch.qos.logback:logback-classic:1.5.9 → 1.5.10.
- Update ch.qos.logback:logback-classic:1.5.10 → 1.5.11.
- Update org.junit:junit-bom:5.11.2 → 5.11.3.
- Update org.xerial:sqlite-jdbc:3.46.1.3 → 3.47.0.0.
- Update ch.qos.logback:logback-classic:1.5.11 → 1.5.12.
- Update nl.jqno.equalsverifier:equalsverifier:3.17.1 → 3.17.2.
- Update nl.jqno.equalsverifier:equalsverifier:3.17.2 → 3.17.3.
- Update io.opentelemetry:opentelemetry-bom:1.43.0 → 1.44.1.
- Update org.xerial:sqlite-jdbc:3.47.0.0 → 3.47.1.0.
- Update nl.jqno.equalsverifier:equalsverifier:3.17.3 → 3.17.4.
- Update jqwik.version:1.9.1 → 1.9.2.
- Update nl.jqno.equalsverifier:equalsverifier:3.17.4 → 3.17.5.
- Update io.opentelemetry:opentelemetry-bom:1.44.1 → 1.45.0.
- Update org.junit:junit-bom:5.11.3 → 5.11.4.
- Update ch.qos.logback:logback-classic:1.5.12 → 1.5.13.
- Update ch.qos.logback:logback-classic:1.5.13 → 1.5.14.
- Update org.freemarker:freemarker:2.3.33 → 2.3.34.
- Update ch.qos.logback:logback-classic:1.5.14 → 1.5.15.
- Update nl.jqno.equalsverifier:equalsverifier:3.17.5 → 3.18.
- Update org.xerial:sqlite-jdbc:3.47.1.0 → 3.47.2.0.
- Update ch.qos.logback:logback-classic:1.5.15 → 1.5.16.
- Update nl.jqno.equalsverifier:equalsverifier:3.18 → 3.18.1.
- Update io.opentelemetry:opentelemetry-bom:1.45.0 → 1.46.0.
- Update org.postgresql:postgresql:42.7.4 → 42.7.5.
- Update org.xerial:sqlite-jdbc:3.47.2.0 → 3.48.0.0.
- Update codecov/codecov-action:5.1.2 → 5.3.1.
- Update nl.jqno.equalsverifier:equalsverifier:3.18.1 → 3.18.2.
- Update org.xerial:sqlite-jdbc:3.48.0.0 → 3.49.1.0.
- Update org.junit:junit-bom:5.11.4 → 5.12.1.
- Update nl.jqno.equalsverifier:equalsverifier:3.18.2 → 3.19.2.
- Update ch.qos.logback:logback-classic:1.5.16 → 1.5.18.
- Update io.opentelemetry:opentelemetry-bom:1.46.0 → 1.48.0.
- Replace role handling. (Backwards incompatible) (Tickets: 81)
2.0.1 Release (2024-10-12Z)
- Update io.opentelemetry:opentelemetry-bom:1.42.0 → 1.42.1.
- Update nl.jqno.equalsverifier:equalsverifier:3.16.2 → 3.17.
- Update org.junit:junit-bom:5.11.0 → 5.11.1.
- Update org.xerial:sqlite-jdbc:3.46.1.0 → 3.46.1.3.
- Update jqwik.version:1.9.0 → 1.9.1.
- Update nl.jqno.equalsverifier:equalsverifier:3.17 → 3.17.1.
- Update org.junit:junit-bom:5.11.1 → 5.11.2.
- Update ch.qos.logback:logback-classic:1.5.8 → 1.5.9.
- Update io.opentelemetry:opentelemetry-bom:1.42.1 → 1.43.0.
- Use more explicit BigInteger checking for schema versions.
2.0.0 Release (2024-09-07Z)
- Allow for passing in SAX parser factories explicitly. (Backwards incompatible)
- Update ch.qos.logback:logback-classic:1.5.7 → 1.5.8.
- Update io.opentelemetry:opentelemetry-bom:1.41.0 → 1.42.0.
1.0.0 Release (2024-09-01Z)
Development Snapshots
At the time of writing, the current unstable development version of the package is 3.2.0-SNAPSHOT.
Development snapshots may be available in the Central Portal Snapshots repository. Snapshots are published to this repository every time the project is built by the project's continuous integration system, but snapshots do expire after around ninety days and so may or may not be available depending on when a build of the package was last triggered.
Manual
This project does not have any user manuals or other documentation beyond what might be present on the page above.
Sources
This project uses Git to manage source code.
Repository: https://www.github.com/io7m-com/darco
$ git clone --recursive https://www.github.com/io7m-com/darco
Issues
This project uses GitHub Issues to track issues.
License
Copyright © 2024 Mark Raynsford <code@io7m.com> https://www.io7m.com Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.