From 52ceb01d3a86f8e7920c5e79821fc8c84ca020e5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 12 Nov 2020 12:19:09 +0600 Subject: [PATCH] remove redundant things from database config --- .../inmo/plagubot/config/DatabaseConfig.kt | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/bot/src/main/kotlin/dev/inmo/plagubot/config/DatabaseConfig.kt b/bot/src/main/kotlin/dev/inmo/plagubot/config/DatabaseConfig.kt index 1d1b4e0..835a548 100644 --- a/bot/src/main/kotlin/dev/inmo/plagubot/config/DatabaseConfig.kt +++ b/bot/src/main/kotlin/dev/inmo/plagubot/config/DatabaseConfig.kt @@ -12,29 +12,15 @@ data class DatabaseConfig( val url: String = "jdbc:sqlite:file:test?mode=memory&cache=shared", val driver: String = JDBC::class.qualifiedName!!, val username: String = "", - val password: String = "", - val initAutomatically: Boolean = true + val password: String = "" ) { @Transient - private lateinit var _database: Database - val database: Database - get() = try { - _database - } catch (e: UninitializedPropertyAccessException) { - Database.connect( - url, - driver, - username, - password - ).also { - _database = it - it.transactionManager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE // Or Connection.TRANSACTION_READ_UNCOMMITTED - } - } - - init { - if (initAutomatically) { - database // init database - } + val database: Database = Database.connect( + url, + driver, + username, + password + ).also { + it.transactionManager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE // Or Connection.TRANSACTION_READ_UNCOMMITTED } }