mirror of
https://github.com/BlockWorldGroup/Ledger-Databases.git
synced 2025-08-17 11:39:43 +08:00
Use enum for database values
- Breaks previous config files
This commit is contained in:
parent
d259bda36b
commit
3b292146b2
@ -14,7 +14,7 @@ Add the following to the bottom of your Ledger config file:
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
[database_extensions]
|
[database_extensions]
|
||||||
h2 = true
|
database = "H2"
|
||||||
```
|
```
|
||||||
|
|
||||||
## MySQL
|
## MySQL
|
||||||
@ -23,7 +23,7 @@ Add the following to the bottom of your Ledger config file:
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
[database_extensions]
|
[database_extensions]
|
||||||
mysql = true
|
database = "MYSQL"
|
||||||
url = ""
|
url = ""
|
||||||
username = ""
|
username = ""
|
||||||
password = ""
|
password = ""
|
||||||
|
@ -3,8 +3,7 @@ package net.quiltservertools.ledger.databases
|
|||||||
import com.github.quiltservertools.libs.com.uchuhimo.konf.ConfigSpec
|
import com.github.quiltservertools.libs.com.uchuhimo.konf.ConfigSpec
|
||||||
|
|
||||||
object DatabaseExtensionSpec : ConfigSpec("database_extensions") {
|
object DatabaseExtensionSpec : ConfigSpec("database_extensions") {
|
||||||
val h2 by optional(false, "h2")
|
val database by optional(Databases.SQLITE, "database")
|
||||||
val mySql by optional(false, "mysql")
|
|
||||||
val userName by optional("root", "username")
|
val userName by optional("root", "username")
|
||||||
val password by optional("", "password")
|
val password by optional("", "password")
|
||||||
val url by optional("localhost", "url")
|
val url by optional("localhost", "url")
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package net.quiltservertools.ledger.databases
|
||||||
|
|
||||||
|
enum class Databases {
|
||||||
|
SQLITE,
|
||||||
|
MYSQL,
|
||||||
|
H2
|
||||||
|
}
|
@ -13,12 +13,12 @@ class LedgerDatabaseExtension : DatabaseExtension {
|
|||||||
override fun getConfigSpecs(): List<ConfigSpec> = listOf(DatabaseExtensionSpec)
|
override fun getConfigSpecs(): List<ConfigSpec> = listOf(DatabaseExtensionSpec)
|
||||||
|
|
||||||
override fun getDatabase(server: MinecraftServer): Database {
|
override fun getDatabase(server: MinecraftServer): Database {
|
||||||
if (Ledger.config[DatabaseExtensionSpec.h2]) {
|
if (Ledger.config[DatabaseExtensionSpec.database] == Databases.H2) {
|
||||||
return Database.connect(
|
return Database.connect(
|
||||||
url = "jdbc:h2:${server.getSavePath(WorldSavePath.ROOT).resolve("ledger.h2").toFile()};MODE=MySQL",
|
url = "jdbc:h2:${server.getSavePath(WorldSavePath.ROOT).resolve("ledger.h2").toFile()};MODE=MySQL",
|
||||||
driver = "org.h2.Driver"
|
driver = "org.h2.Driver"
|
||||||
)
|
)
|
||||||
} else if (Ledger.config[DatabaseExtensionSpec.mySql]) {
|
} else if (Ledger.config[DatabaseExtensionSpec.database] == Databases.MYSQL) {
|
||||||
return Database.connect(
|
return Database.connect(
|
||||||
url = "jdbc:mysql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true",
|
url = "jdbc:mysql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true",
|
||||||
driver = "com.mysql.cj.jdbc.Driver",
|
driver = "com.mysql.cj.jdbc.Driver",
|
||||||
@ -30,9 +30,9 @@ class LedgerDatabaseExtension : DatabaseExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getIdentifier(): Identifier {
|
override fun getIdentifier(): Identifier {
|
||||||
if (Ledger.config.contains(DatabaseExtensionSpec.h2) && Ledger.config[DatabaseExtensionSpec.h2]) {
|
if (Ledger.config[DatabaseExtensionSpec.database] == Databases.H2) {
|
||||||
return h2Identifier
|
return h2Identifier
|
||||||
} else if (Ledger.config.contains(DatabaseExtensionSpec.mySql) && Ledger.config[DatabaseExtensionSpec.mySql]) {
|
} else if (Ledger.config[DatabaseExtensionSpec.database] == Databases.MYSQL) {
|
||||||
return mySqlIdentifier
|
return mySqlIdentifier
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user