This module allows to get up HikariCP connection pool at application start.
<repositories>
<repository>
<id>exktor</id>
<url>https://maven.pkg.github.com/paslavsky/exktor</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.paslavsky</groupId>
<artifactId>ktor-sql</artifactId>
<version>${exktor.version}</version>
</dependency>
</dependencies>
repositories {
maven {
url = uri("https://maven.pkg.github.com/paslavsky/exktor")
}
}
dependencies {
implementation "net.paslavsky:ktor-sql:$exktorVersion"
}
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
Anywhere inside Application
context you could use variable dataSource
(javax.sql.DataSource
) to access to the connection pool.
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