jasync-sql is a Simple, Netty based, asynchronous, performant and reliable database drivers for PostgreSQL and MySQL written in Kotlin.
Getting started
// Connection to MySQL DB
Connection connection = MySQLConnectionBuilder.createConnectionPool(
"jdbc:mysql://$host:$port/$database?user=$username&password=$password");
// Connection to PostgreSQL DB
Connection connection = PostgreSQLConnectionBuilder.createConnectionPool(
"jdbc:postgresql://$host:$port/$database?user=$username&password=$password");
// Execute query
CompletableFuture<QueryResult> future = connection.sendPreparedStatement("select * from table");
// work with result ...
// Close the connection pool
connection.disconnect().get()
See a full example at jasync-mysql-example and jasync-postgresql-example.
More samples on the samples dir.
For docs and info see the wiki.
Download
Maven
<!-- mysql -->
<dependency>
<groupId>com.github.jasync-sql</groupId>
<artifactId>jasync-mysql</artifactId>
<version>2.0.3</version>
</dependency>
<!-- postgresql -->
<dependency>
<groupId>com.github.jasync-sql</groupId>
<artifactId>jasync-postgresql</artifactId>
<version>2.0.3</version>
</dependency>
Gradle
dependencies {
// mysql
compile 'com.github.jasync-sql:jasync-mysql:2.0.3'
// postgresql
compile 'com.github.jasync-sql:jasync-postgresql:2.0.3'
}
Overview
This project is a port of mauricio/postgresql-async to Kotlin.
Why? Because the original lib is not maintained anymore, We use it in ob1k, and would like to remove the Scala dependency in ob1k.
If you want information specific to the drivers, check the PostgreSQL README and the MySQL README.
You can view the project's change log here.
Follow us on twitter: @jasyncs.
DateTime:
Version 1.x always returns JodaTime when dealing with date types and not the java.util.Date
class nor jdk-8 dates.
Version 2.x works with java 8 DateTime objects (java.time.LocalDateTime
and such).
This post can help with migration.
Who is using it
- R2DBC
- Spring Data R2DBC
- Vert.x
- micronaut
- Outbrain/ob1k-db
- https://github.com/humb1t/jpom
- Zeko Data Mapper and Zeko SQL Builder
- vertx-jooq async module
- ScalikeJDBC Async
- Quill
- Jasync SQL Extensions
Add your name here!
Is it used in production on large scale?
The graph above is from only couple of services using it. Y-Axis is # of queries per minute.
There is also a TechEmpower test using ktor
and jasync-sql
.
Zeko SQL Builder compared jasync to hikary and vertex:
Support
- Check FAQ or Known Issues or google.
- Open an issue here: https://github.com/jasync-sql/jasync-sql/issues
- Chat on gitter: https://gitter.im/jasync-sql/support
- Ask a question in StackOverflow with jasync-sql tag.
More links
- How we cloned the original lib.
- https://github.com/mauricio/postgresql-async - The original (deprecated) lib.
- Async database access with MySQL, Kotlin and jasync-sql.
- Issue with NUMERIC.
- jasync-sql + javalin example.
- jasync-sql + ktor + coroutines example.
- jasync-sql + spring + kotlin example.
- How to implement an Object Pool with an Actor in Kotlin.
- Coroutines usage.
- Spring Data R2DBC video.
- JDBC for Spring WebFlux: Spring Data R2DBC.
- Spring WebFlux는 어떻게 적은 리소스로 많은 트래픽을 감당할까?.
Contributing
Pull requests are welcome!
See CONTRIBUTING.