A PostgreSQL client library written in pure Kotlin, made for use with Coroutines
KotgreSQL's I/O is completely non-blocking (built with NIO) and suspend functions. You can do all interactions with the database from Coroutines without ever blocking the thread.
See the examples section below to get started
Look ma, no Netty, no Reactor framework, no Spring Data! Just plain NIO, no dependencies apart from kotlin-coroutines. Only 127kB Jar File size (as of release 0.1).
While portable database frameworks are a great thing for management presentations, in practical applications it is much better to focus on the strenghts and features of one particular product, so you can use all its features exactly as intended without additional layers of bloat in between.
If you ever need to switch to a different DB, this will probably be a big migration project anyway, regardless whether or not you use a (theoretically) portable Java framework.
This is why KotgreSQL is built and designed from the ground up for use with PostgreSQL only.
- Supports PostgreSQL 12, 13, 14 and 15
- Ready for use with Amazon RDS for PostgreSQL
- Authentication methods: cleartext password, md5 and SCRAM-SHA256
- Simple queries and prepared statements
- Connection Pool (inspired by HikariCP)
- Migration tool (inspired by Flyway)
val postgresClient = PostgresClient(
host = "localhost",
database = "mydb",
username = "me",
password = "XXX"
)
data class Bicycle(
val id: Int,
val name: String,
val price: Int
)
postgresClient.withConnection { connection ->
val bicycles = connection
.executeQuery("select id,name,price from bicycles")
.mapTo<Bicycle>()
}
postgresClient.withConnection { connection ->
connection.prepareStatement("""
select id,name,price from bicycle
where name = $1
and price < $2
""".trimIndent()
).use { stmt ->
val bicycles = stmt.executeQuery("Topstone", 2000)
.mapTo<Bicycle>()
}
}
A Kotlin-native PostgreSQL client library made for use with Coroutines. You should use it when when you work with Coroutines and you want to avoid blocking the main thread, but you don't want to use a big bloated framework such as Spring Data / R2DBC
No, it's made for the JVM platform only, as it relies heavily on NIO.