mirror of
https://github.com/InsanusMokrassar/PlaguBot.git
synced 2024-11-22 07:33:46 +00:00
add option waitForConnection in database config
This commit is contained in:
parent
ab0578b312
commit
dfbc7be6f2
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## 2.3.0
|
## 2.3.0
|
||||||
|
|
||||||
|
* `Bot`:
|
||||||
|
* Add option `waitForConnection` in database config
|
||||||
|
|
||||||
## 2.2.0
|
## 2.2.0
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
@ -6,6 +6,7 @@ import org.jetbrains.exposed.sql.Database
|
|||||||
import org.jetbrains.exposed.sql.transactions.transactionManager
|
import org.jetbrains.exposed.sql.transactions.transactionManager
|
||||||
import org.koin.core.scope.Scope
|
import org.koin.core.scope.Scope
|
||||||
import org.sqlite.JDBC
|
import org.sqlite.JDBC
|
||||||
|
import java.lang.Exception
|
||||||
import java.sql.Connection
|
import java.sql.Connection
|
||||||
|
|
||||||
inline val Scope.database: Database?
|
inline val Scope.database: Database?
|
||||||
@ -16,15 +17,30 @@ 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 waitForConnection: Boolean = true
|
||||||
) {
|
) {
|
||||||
@Transient
|
@Transient
|
||||||
val database: Database = Database.connect(
|
val database: Database by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
|
||||||
url,
|
while (true) {
|
||||||
driver,
|
return@lazy try {
|
||||||
username,
|
Database.connect(
|
||||||
password
|
url,
|
||||||
).also {
|
driver,
|
||||||
it.transactionManager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE // Or Connection.TRANSACTION_READ_UNCOMMITTED
|
username,
|
||||||
|
password
|
||||||
|
).also {
|
||||||
|
it.transactionManager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE // Or Connection.TRANSACTION_READ_UNCOMMITTED
|
||||||
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
if (waitForConnection) {
|
||||||
|
Thread.sleep(1000L)
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
error("Unable to get database by some reason")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"driver": "org.sqlite.JDBC",
|
"driver": "org.sqlite.JDBC",
|
||||||
"username": "OPTIONAL username",
|
"username": "OPTIONAL username",
|
||||||
"password": "OPTIONAL password",
|
"password": "OPTIONAL password",
|
||||||
"initAutomatically": false
|
"waitForConnection": true
|
||||||
},
|
},
|
||||||
"botToken": "1234567890:ABCDEFGHIJKLMNOP_qrstuvwxyz12345678",
|
"botToken": "1234567890:ABCDEFGHIJKLMNOP_qrstuvwxyz12345678",
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
Loading…
Reference in New Issue
Block a user