From 9b4effa39ee11b7e23edf3374c7b6c8c74f24665 Mon Sep 17 00:00:00 2001 From: Hossain Khan Date: Sat, 18 Nov 2023 12:03:45 -0500 Subject: [PATCH] Code modification using Copilot --- .idea/vcs.xml | 1 - .../postgresqldelight/SportsRepository.kt | 23 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 288b36b..94a25f7 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,7 +1,6 @@ - \ No newline at end of file diff --git a/src/main/kotlin/dev/hossain/postgresqldelight/SportsRepository.kt b/src/main/kotlin/dev/hossain/postgresqldelight/SportsRepository.kt index 3f8ad35..d1341f3 100644 --- a/src/main/kotlin/dev/hossain/postgresqldelight/SportsRepository.kt +++ b/src/main/kotlin/dev/hossain/postgresqldelight/SportsRepository.kt @@ -33,14 +33,23 @@ class SportsRepository constructor( SportsDatabase.Schema.create(driver) } + + /** + * Creates a [DataSource] using [HikariDataSource]. + * @param appConfig the [AppConfig] required to create the [DataSource]. + */ private fun getDataSource(appConfig: AppConfig): DataSource { - val hikariConfig = HikariConfig() // https://jdbc.postgresql.org/documentation/use/ - hikariConfig.setJdbcUrl("jdbc:postgresql://${appConfig.dbHost}/${appConfig.dbName}") - hikariConfig.driverClassName = "org.postgresql.Driver" - hikariConfig.username = appConfig.dbUsername - hikariConfig.password = appConfig.dbPassword - - return HikariDataSource(hikariConfig) + val config = HikariConfig().apply { + jdbcUrl = "jdbc:postgresql://${appConfig.dbHost}/${appConfig.dbName}" + driverClassName = "org.postgresql.Driver" + username = appConfig.dbUsername + password = appConfig.dbPassword + maximumPoolSize = 3 + isAutoCommit = false + transactionIsolation = "TRANSACTION_REPEATABLE_READ" + validate() + } + return HikariDataSource(config) } } \ No newline at end of file