Skip to content

Latest commit

 

History

History
90 lines (78 loc) · 2.66 KB

README.md

File metadata and controls

90 lines (78 loc) · 2.66 KB

HikariCP extension for Ktor

Download Build Status GitHub License

This module allows to get up HikariCP connection pool at application start.

Quick start

Maven

<repositories>
    <repository>
      <id>jcenter</id>
      <name>jcenter</name>
      <url>http://jcenter.bintray.com</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>net.paslavsky</groupId>
        <artifactId>ktor-sql</artifactId>
        <version>${exktor.version}</version>
    </dependency>
</dependencies>

Gradle

repositories {
  jcenter()
}

dependencies {
  implementation "net.paslavsky:ktor-sql:$exktorVersion"
}

Connection pool configuration

fun Application.module() {
    install(SqlFeature) { // this: HikariConfig
        // ...
    }
}

Almost all configs could be configured at the configuration file:

  • dataSource.dataSourceClassName
  • dataSource.jdbcUrl
  • dataSource.username
  • dataSource.password
  • dataSource.autoCommit
  • dataSource.connectionTimeout
  • dataSource.idleTimeout
  • dataSource.maxLifetime
  • dataSource.connectionTestQuery
  • dataSource.minimumIdle
  • dataSource.maximumPoolSize
  • dataSource.poolName
  • dataSource.initializationFailTimeout
  • dataSource.isolateInternalQueries
  • dataSource.allowPoolSuspension
  • dataSource.readOnly
  • dataSource.registerMbeans
  • dataSource.catalog
  • dataSource.connectionInitSql
  • dataSource.driverClassName
  • dataSource.transactionIsolation
  • dataSource.validationTimeout
  • dataSource.leakDetectionThreshold
  • dataSource.schema

For more information please read HikaryCP official documentation.

Note: Programmatic configuration will override configs from configuration file

Access to the connection pool

Anywhere inside Application context you could use variable dataSource (javax.sql.DataSource) to access to the connection pool.

Events

ktor-sql module listen to standard ktor events to create/close connection poll and producing own events:

  • ApplicationStarted
    • DBConnecting - before create connection pool
    • DBConnected - when connection pool was successfully created
  • ApplicationStopPreparing
    • DBClosing - before closing connection pool
    • DBClosed - connection poll was closed