Skip to content

alaisi/postgres-async-driver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pg-async-driver - Asynchronous PostgreSQL Java driver

Pg-async-driver is a non-blocking Java driver for PostgreSQL. The driver supports connection pooling, prepared statements, transactions and all standard SQL types.

Download

Pg-async-driver is available on Maven Central.

<dependency>
    <groupId>com.github.alaisi.pgasync</groupId>
    <artifactId>pg-async-driver</artifactId>
    <version>0.1</version>
</dependency>

Usage

Hello world

ConnectionPool pool = ...;
pool.query("SELECT 'Hello world!' AS message", new ResultHandler() {
    @Override
    public void onResult(ResultSet result) {
        System.out.println(result.get(0).getString("message"));
    }
}, new ErrorHandler() {
    @Override
    public void onError(Throwable error) {
        error.printStackTrace();
    }
});

Or with Java 8:

ConnectionPool pool = ...;
pool.query("SELECT 'Hello world!' AS message",
    (result) -> System.out.println(result.get(0).getString("message")),
    (error) -> error.printStackTrace() );

Connection pools

Connection pools are created with com.github.pgasync.ConnectionPoolBuilder

ConnectionPool pool = return new ConnectionPoolBuilder()
    .database("db")
    .username("user")
    .password("pass")
    .poolSize(20)
    .build();

Each connection pool will start one IO thread used in communicating with PostgreSQL backend.

Prepared statements

TODO

Transactions

TODO

References

About

Asynchronous PostgreSQL Java driver

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 10

Languages