Skip to content

Kotysa for JDBC

Dependency

kotysa-jdbc is a single dependency you can add to your project.

groovy
repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.ufoss.kotysa:kotysa-jdbc:3.2.2'

    // Choose the right JDBC driver for your database
    implementation 'com.h2database:h2:xyz'
    implementation 'mysql:mysql-connector-java:xyz'
    implementation 'com.microsoft.sqlserver:mssql-jdbc:xyz'
    implementation 'org.mariadb.jdbc:mariadb-java-client:xyz'
    implementation 'org.postgresql:postgresql:xyz'
    implementation '"com.oracle.database.jdbc:ojdbc8:xyz'
}

Check this sample project for a Ktor Netty application with a JDBC backend accessed via kotysa-jdbc.

Check this sample project for a Quarkus Resteasy application with a JDBC backend accessed via kotysa-jdbc.

Usage

kotysa-jdbc provides a SQL client on top of JVM's included jdbc, it can be obtained via an Extension function directly on javax.sql.DataSource.

kotlin
class Repository(dataSource: DataSource, tables: H2Tables) {

	private val sqlClient = dataSource.sqlClient(tables)

	// enjoy sqlClient for jdbc :)
}

Supported databases

Transaction

In kotysa-jdbc, transaction is available directly on the sqlClient.

kotlin
sqlClient.transactional { transaction ->
    // execute your queries inside this transaction
}

Released under The Unlicense.