mirror of
https://github.com/InsanusMokrassar/PlaguBot.git
synced 2024-11-22 07:33:46 +00:00
remove redundant things from database config
This commit is contained in:
parent
27fd0607cc
commit
52ceb01d3a
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user