Created
July 5, 2021 15:15
-
-
Save renaudmathieu/b37bfe772cfe9f47ff6613a0309d1396 to your computer and use it in GitHub Desktop.
ktor_part3_AppDatabase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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