Connection Pooling
Reuse PostgreSQL connections and execute concurrent asynchronous work.
Asynchronous PostgreSQL Java driver
A non-blocking PostgreSQL driver with connection pooling, prepared statements, transactions, standard SQL type support, and custom converters.
pool.completeQuery(
"select count(*) cnt from cp_test"
).thenAccept(resultSet -> {
int count = resultSet.at(0).getInt("cnt");
});
Install
The project is published as a Gradle source dependency. Add the Git repository to `settings.gradle.kts`, then depend on the module from your build file.
sourceControl {
gitRepository(uri("https://github.com/AlekseiDudchenko/postgres-async-driver.git")) {
producesModule("com.github.pgasync:postgres-async-driver")
}
}
dependencies {
implementation("com.github.pgasync:postgres-async-driver:v1.0.5")
}
Usage
The public API lives in `com.pgasync`; implementation classes live under `com.github.pgasync`.
Connectible pool = new NettyConnectibleBuilder()
.database("postgres")
.username("postgres")
.password("postgres")
.ssl(true)
.maxConnections(4)
.pool();
pool.completeQuery("select count(*) cnt from cp_test")
.thenAccept(resultSet -> {
Row row = resultSet.at(0);
int count = row.getInt("cnt");
});
Reuse PostgreSQL connections and execute concurrent asynchronous work.
Bind parameters and keep query execution explicit at the API boundary.
Begin, commit, and roll back transactional units with future-based flows.
Extend type handling for application-specific PostgreSQL values.
Testing
Tests use JUnit 4 and Testcontainers for PostgreSQL. Start Docker Desktop first; Testcontainers will pull and run `postgres:11` automatically.
docker info
.\gradlew.bat test --no-daemon