remove redundant things from database config

This commit is contained in:
InsanusMokrassar 2020-11-12 12:19:09 +06:00
parent 27fd0607cc
commit 52ceb01d3a

View File

@ -12,29 +12,15 @@ data class DatabaseConfig(
val url: String = "jdbc:sqlite:file:test?mode=memory&cache=shared", val url: String = "jdbc:sqlite:file:test?mode=memory&cache=shared",
val driver: String = JDBC::class.qualifiedName!!, val driver: String = JDBC::class.qualifiedName!!,
val username: String = "", val username: String = "",
val password: String = "", val password: String = ""
val initAutomatically: Boolean = true
) { ) {
@Transient @Transient
private lateinit var _database: Database val database: Database = Database.connect(
val database: Database
get() = try {
_database
} catch (e: UninitializedPropertyAccessException) {
Database.connect(
url, url,
driver, driver,
username, username,
password password
).also { ).also {
_database = it
it.transactionManager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE // Or Connection.TRANSACTION_READ_UNCOMMITTED it.transactionManager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE // Or Connection.TRANSACTION_READ_UNCOMMITTED
} }
} }
init {
if (initAutomatically) {
database // init database
}
}
}