Skip to content

Configuration

Kuery Client has two separate configuration layers:

  1. The Gradle plugin configures compile-time SQL transformation and diagnostics.
  2. The R2DBC/JDBC client builder configures runtime database access, conversion, and observation.

Gradle plugin

Apply the plugin to every JVM or Android/JVM module that contains a sql { ... } call:

kotlin
plugins {
    id("dev.hsbrysk.kuery-client") version "1.1.0"
}

The compiler plugin is applied only to JVM and Android/JVM compilations. Maven is not currently supported. In a multi-module build, applying the plugin only to the application module is not enough when repository code lives in another module.

Options

OptionTypeDefaultPurposeAccepted values
autoTrimIndentBooleanfalseApplies trimIndent() automatically to strings passed to + / add()
sqlSyntaxCheckStringunsetEnables compile-time SQL parsing and optionally selects a dialect
  • generic
  • ansi
  • oracle
  • mysql
  • sqlserver
  • mariadb
  • postgresql
  • h2

Values are case-insensitive and surrounding whitespace is ignored. Any other value fails the Gradle build.

strictBooleanfalseEscalates SQL-safety diagnostics from warnings to errors

For example:

kotlin
kueryClient {
    autoTrimIndent = true
    sqlSyntaxCheck = "postgresql"
    strict = true
}

Recommended settings and planned defaults

These options were added after Kuery Client's initial releases and remain opt-in today to avoid changing the behavior of existing projects. They are intended to become the defaults in a future release, equivalent to:

kotlin
kueryClient {
    autoTrimIndent = true
    sqlSyntaxCheck = "mysql"
    strict = true
}

New projects can enable them now. Replace mysql with the project's dialect when needed; dialect validation is stricter but can report false positives for uncommon vendor-specific SQL.

See Building SQL, Compile-Time Checks, and SQL Syntax Check for the exact behavior.

Runtime client builder

The R2DBC and JDBC builders expose the same configuration concepts, with a different required connection object.

Builder methodR2DBCJDBCDefault
connectionFactory(...)requirednone
dataSource(...)requirednone
converters(...)availableavailableempty list
observationRegistry(...)availableavailableobservation disabled
observationConvention(...)availableavailablebuilt-in convention
enableAutoSqlIdGeneration(...)availableavailabletrue when an observation registry is set; otherwise false

Calling build() without the required ConnectionFactory or DataSource throws an IllegalArgumentException. Both built clients are designed to be shared across the application.

kotlin
val kueryClient: KueryClient = SpringR2dbcKueryClient.builder()
    .connectionFactory(connectionFactory)
    .converters(listOf(MyWritingConverter(), MyReadingConverter()))
    .observationRegistry(observationRegistry)
    .build()
kotlin
val kueryClient: KueryBlockingClient = SpringJdbcKueryClient.builder()
    .dataSource(dataSource)
    .converters(listOf(MyWritingConverter(), MyReadingConverter()))
    .observationRegistry(observationRegistry)
    .build()

See Type Conversion and Observation for the optional runtime settings.