Database drivers using Kotlin™ to drive database communication. The library provides both blocking and non-blocking solutions for database communication. The coroutine based solution uses Ktor networking under the hood which implements non-blocking selector socket channel connections. For the blocking solution, basic java sockets (as seen in JDBC based libraries) are used to facilitate database communications. This library is heavily inspired by Rust's SQLx and the connection spec in C#.
Currently, there is only initial support for Postgresql and plans for other freely available databases, but other JDBC compliant databases might also be added in the future.
dependencies {
implementation("io.github.clasicrando:kdbc-postgresql:0.0.3")
}
val connectOptions = PgConnectOptions(
host = "localhost",
port = 5342U,
username = "username",
password = "yourSecretPassword",
applicationName = "MyFirstKdbcProject"
)
val connection = Postgres.asyncConnection(connectOption = connectOptions)
val text: String = connection.createQuery("SELECT 'KDBC Docs'")
.fetchScalar()
println(text) // KDBC Docs
connection.createPreparedQuery("CALL your_stored_procedure($1, $2)")
.bind(1)
.bind("KDBC Docs")
.execute()
connection.close()