Skip to content

Commit 3b29214

Browse files
author
yitzy299
committed
Use enum for database values
- Breaks previous config files
1 parent d259bda commit 3b29214

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Add the following to the bottom of your Ledger config file:
1414

1515
```toml
1616
[database_extensions]
17-
h2 = true
17+
database = "H2"
1818
```
1919

2020
## MySQL
@@ -23,7 +23,7 @@ Add the following to the bottom of your Ledger config file:
2323

2424
```toml
2525
[database_extensions]
26-
mysql = true
26+
database = "MYSQL"
2727
url = ""
2828
username = ""
2929
password = ""

src/main/kotlin/net.quiltservertools.ledger.databases/DatabaseExtensionSpec.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package net.quiltservertools.ledger.databases
33
import com.github.quiltservertools.libs.com.uchuhimo.konf.ConfigSpec
44

55
object DatabaseExtensionSpec : ConfigSpec("database_extensions") {
6-
val h2 by optional(false, "h2")
7-
val mySql by optional(false, "mysql")
6+
val database by optional(Databases.SQLITE, "database")
87
val userName by optional("root", "username")
98
val password by optional("", "password")
109
val url by optional("localhost", "url")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package net.quiltservertools.ledger.databases
2+
3+
enum class Databases {
4+
SQLITE,
5+
MYSQL,
6+
H2
7+
}

src/main/kotlin/net.quiltservertools.ledger.databases/LedgerDatabaseExtension.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ class LedgerDatabaseExtension : DatabaseExtension {
1313
override fun getConfigSpecs(): List<ConfigSpec> = listOf(DatabaseExtensionSpec)
1414

1515
override fun getDatabase(server: MinecraftServer): Database {
16-
if (Ledger.config[DatabaseExtensionSpec.h2]) {
16+
if (Ledger.config[DatabaseExtensionSpec.database] == Databases.H2) {
1717
return Database.connect(
1818
url = "jdbc:h2:${server.getSavePath(WorldSavePath.ROOT).resolve("ledger.h2").toFile()};MODE=MySQL",
1919
driver = "org.h2.Driver"
2020
)
21-
} else if (Ledger.config[DatabaseExtensionSpec.mySql]) {
21+
} else if (Ledger.config[DatabaseExtensionSpec.database] == Databases.MYSQL) {
2222
return Database.connect(
2323
url = "jdbc:mysql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true",
2424
driver = "com.mysql.cj.jdbc.Driver",
@@ -30,9 +30,9 @@ class LedgerDatabaseExtension : DatabaseExtension {
3030
}
3131

3232
override fun getIdentifier(): Identifier {
33-
if (Ledger.config.contains(DatabaseExtensionSpec.h2) && Ledger.config[DatabaseExtensionSpec.h2]) {
33+
if (Ledger.config[DatabaseExtensionSpec.database] == Databases.H2) {
3434
return h2Identifier
35-
} else if (Ledger.config.contains(DatabaseExtensionSpec.mySql) && Ledger.config[DatabaseExtensionSpec.mySql]) {
35+
} else if (Ledger.config[DatabaseExtensionSpec.database] == Databases.MYSQL) {
3636
return mySqlIdentifier
3737

3838
}

0 commit comments

Comments
 (0)