Skip to content

Instantly share code, notes, and snippets.

@renaudmathieu
Created July 5, 2021 15:15
Show Gist options
  • Save renaudmathieu/b37bfe772cfe9f47ff6613a0309d1396 to your computer and use it in GitHub Desktop.
Save renaudmathieu/b37bfe772cfe9f47ff6613a0309d1396 to your computer and use it in GitHub Desktop.
ktor_part3_AppDatabase
@KtorExperimentalAPI
class AppDatabase(
private val config: ApplicationConfig
) {
lateinit var dataSource: DataSource
fun init() {
connectionPool()
orm()
}
private fun connectionPool() {
val dbConfig = this.config.config("ktor.database")
val config = HikariConfig().apply {
jdbcUrl = dbConfig.property("connection.jdbc").getString()
username = dbConfig.property("connection.user").getString()
password = dbConfig.property("connection.password").getString()
isAutoCommit = false
maximumPoolSize = 3
transactionIsolation = "TRANSACTION_REPEATABLE_READ"
validate()
}
dataSource = HikariDataSource(config)
}
private fun orm() = Database.connect(dataSource)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment