mirror of
https://github.com/BlockWorldGroup/Ledger-Databases.git
synced 2025-08-17 11:39:43 +08:00
Add support for database properties in config file
This commit is contained in:
parent
0690358848
commit
236ea2e26b
47
.github/workflows/build.yml
vendored
47
.github/workflows/build.yml
vendored
@ -1,47 +0,0 @@
|
|||||||
# Automatically build the project and run any configured tests for every push
|
|
||||||
# and submitted pull request. This can help catch issues that only occur on
|
|
||||||
# certain platforms or Java versions, and provides a first line of defence
|
|
||||||
# against bad commits.
|
|
||||||
|
|
||||||
name: build
|
|
||||||
on: [pull_request, push]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
# Use these Java versions
|
|
||||||
java: [
|
|
||||||
16 # Minimum supported by Minecraft
|
|
||||||
]
|
|
||||||
# and run on both Linux and Windows
|
|
||||||
os: [ubuntu-20.04, windows-latest]
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
|
||||||
- name: checkout repository
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: validate gradle wrapper
|
|
||||||
uses: gradle/wrapper-validation-action@v1
|
|
||||||
- name: setup jdk ${{ matrix.java }}
|
|
||||||
uses: actions/setup-java@v1
|
|
||||||
with:
|
|
||||||
java-version: ${{ matrix.java }}
|
|
||||||
- name: make gradle wrapper executable
|
|
||||||
if: ${{ runner.os != 'Windows' }}
|
|
||||||
run: chmod +x ./gradlew
|
|
||||||
- name: Download Ledger
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
repository: 'QuiltServerTools/Ledger'
|
|
||||||
ref: 'master'
|
|
||||||
path: 'ledger'
|
|
||||||
- name: Publish Ledger to mavenlocal
|
|
||||||
run: cd ./ledger && ./gradlew publishToMavenLocal && cd ..
|
|
||||||
- name: build
|
|
||||||
run: ./gradlew build
|
|
||||||
- name: capture build artifacts
|
|
||||||
if: ${{ runner.os == 'Linux' && matrix.java == '16' }}
|
|
||||||
uses: actions/upload-artifact@v2
|
|
||||||
with:
|
|
||||||
name: Artifacts
|
|
||||||
path: build/libs/
|
|
20
README.md
20
README.md
@ -27,6 +27,26 @@ database = "MYSQL"
|
|||||||
url = ""
|
url = ""
|
||||||
username = ""
|
username = ""
|
||||||
password = ""
|
password = ""
|
||||||
|
properties = []
|
||||||
```
|
```
|
||||||
|
|
||||||
`url`: Must be URL of database with `/<database_name>` appended. An example URL would be `localhost/ledger`. You can optionally add port information such as `localhost:3000/ledger`
|
`url`: Must be URL of database with `/<database_name>` appended. An example URL would be `localhost/ledger`. You can optionally add port information such as `localhost:3000/ledger`
|
||||||
|
|
||||||
|
## PostgreSQL
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[database_extensions]
|
||||||
|
database = "MYSQL"
|
||||||
|
url = ""
|
||||||
|
username = ""
|
||||||
|
password = ""
|
||||||
|
properties = []
|
||||||
|
```
|
||||||
|
|
||||||
|
## Connector properties
|
||||||
|
|
||||||
|
For some databases, such as MySQL, you can provide properties to the database connector. For each property, add a string entry to the `properties` array.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
properties = ["useJDBCCompliantTimezoneShift=true", "useLegacyDatetimeCode=false", "serverTimezone=UTC"]
|
||||||
|
```
|
||||||
|
10
build.gradle
10
build.gradle
@ -34,7 +34,7 @@ dependencies {
|
|||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
|
||||||
// Yes this has to be capitalised
|
// Yes this has to be capitalised
|
||||||
modImplementation "com.github.quiltservertools:Ledger:1.2.0"
|
modImplementation "com.github.quiltservertools:ledger:1.2.0"
|
||||||
|
|
||||||
modImplementation "net.fabricmc:fabric-language-kotlin:1.7.0+kotlin.1.6.0"
|
modImplementation "net.fabricmc:fabric-language-kotlin:1.7.0+kotlin.1.6.0"
|
||||||
|
|
||||||
@ -79,13 +79,7 @@ jar {
|
|||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
mavenJava(MavenPublication) {
|
mavenJava(MavenPublication) {
|
||||||
// add all the jars that should be included when publishing to maven
|
from(components["java"])
|
||||||
artifact(remapJar) {
|
|
||||||
builtBy remapJar
|
|
||||||
}
|
|
||||||
artifact(sourcesJar) {
|
|
||||||
builtBy remapSourcesJar
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://fabricmc.net/versions.html
|
# check these on https://fabricmc.net/versions.html
|
||||||
minecraft_version=1.18
|
minecraft_version=1.18.1
|
||||||
yarn_mappings=1.18+build.1
|
yarn_mappings=1.18.1+build.2
|
||||||
loader_version=0.12.5
|
loader_version=0.12.11
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.0.1
|
mod_version = 1.1.0
|
||||||
maven_group = net.quiltservertools
|
maven_group = net.quiltservertools
|
||||||
archives_base_name = ledger-databases
|
archives_base_name = ledger-databases
|
||||||
|
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
package net.quiltservertools.ledger.databases
|
|
||||||
|
|
||||||
enum class Databases {
|
|
||||||
SQLITE,
|
|
||||||
MYSQL,
|
|
||||||
H2,
|
|
||||||
POSTGRESQL
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
package net.quiltservertools.ledger.databases
|
|
||||||
|
|
||||||
import com.github.quiltservertools.ledger.Ledger
|
|
||||||
import com.github.quiltservertools.ledger.api.DatabaseExtension
|
|
||||||
import com.github.quiltservertools.libs.com.uchuhimo.konf.ConfigSpec
|
|
||||||
import net.minecraft.server.MinecraftServer
|
|
||||||
import net.minecraft.util.Identifier
|
|
||||||
import net.minecraft.util.WorldSavePath
|
|
||||||
import org.jetbrains.exposed.sql.Database
|
|
||||||
import kotlin.io.path.pathString
|
|
||||||
|
|
||||||
class LedgerDatabaseExtension : DatabaseExtension {
|
|
||||||
override fun getConfigSpecs(): List<ConfigSpec> = listOf(DatabaseExtensionSpec)
|
|
||||||
|
|
||||||
override fun getDatabase(server: MinecraftServer): Database {
|
|
||||||
return when (Ledger.config[DatabaseExtensionSpec.database]) {
|
|
||||||
Databases.SQLITE -> Database.connect(
|
|
||||||
url = "jdbc:sqlite:${server.getSavePath(WorldSavePath.ROOT).resolve("ledger.sqlite").pathString}",
|
|
||||||
)
|
|
||||||
Databases.H2 -> Database.connect(
|
|
||||||
url = "jdbc:h2:${server.getSavePath(WorldSavePath.ROOT).resolve("ledger.h2").toFile()};MODE=MySQL"
|
|
||||||
)
|
|
||||||
Databases.MYSQL -> Database.connect(
|
|
||||||
url = "jdbc:mysql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true",
|
|
||||||
user = Ledger.config[DatabaseExtensionSpec.userName],
|
|
||||||
password = Ledger.config[DatabaseExtensionSpec.password]
|
|
||||||
)
|
|
||||||
Databases.POSTGRESQL -> Database.connect(
|
|
||||||
url = "jdbc:postgresql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true",
|
|
||||||
user = Ledger.config[DatabaseExtensionSpec.userName],
|
|
||||||
password = Ledger.config[DatabaseExtensionSpec.password]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getIdentifier(): Identifier = when (Ledger.config[DatabaseExtensionSpec.database]) {
|
|
||||||
Databases.MYSQL -> Ledger.identifier("mysql_extension")
|
|
||||||
Databases.H2 -> Ledger.identifier("h2_extension")
|
|
||||||
Databases.POSTGRESQL -> Ledger.identifier("postgresql_extension")
|
|
||||||
else -> Ledger.identifier(Ledger.DEFAULT_DATABASE)
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,4 +7,5 @@ object DatabaseExtensionSpec : ConfigSpec("database_extensions") {
|
|||||||
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")
|
||||||
}
|
val properties by optional(listOf<String>(), "properties")
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package net.quiltservertools.ledger.databases
|
||||||
|
|
||||||
|
import net.quiltservertools.ledger.databases.databases.*
|
||||||
|
|
||||||
|
enum class Databases(val database: LedgerDatabase) {
|
||||||
|
SQLITE(SQLite),
|
||||||
|
MYSQL(MySQL),
|
||||||
|
H2(H2Database),
|
||||||
|
POSTGRESQL(PostgreSQL)
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package net.quiltservertools.ledger.databases
|
||||||
|
|
||||||
|
import com.github.quiltservertools.ledger.Ledger
|
||||||
|
import com.github.quiltservertools.ledger.api.DatabaseExtension
|
||||||
|
import com.github.quiltservertools.libs.com.uchuhimo.konf.ConfigSpec
|
||||||
|
import net.minecraft.server.MinecraftServer
|
||||||
|
import net.minecraft.util.Identifier
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
|
|
||||||
|
class LedgerDatabaseExtension : DatabaseExtension {
|
||||||
|
override fun getConfigSpecs(): List<ConfigSpec> = listOf(DatabaseExtensionSpec)
|
||||||
|
|
||||||
|
override fun getDatabase(server: MinecraftServer): Database {
|
||||||
|
return Ledger.config[DatabaseExtensionSpec.database].database.getDatabase(server)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getIdentifier(): Identifier = Ledger.config[DatabaseExtensionSpec.database].database.getDatabaseIdentifier()
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package net.quiltservertools.ledger.databases.databases
|
||||||
|
|
||||||
|
import com.github.quiltservertools.ledger.Ledger
|
||||||
|
import net.minecraft.server.MinecraftServer
|
||||||
|
import net.minecraft.util.WorldSavePath
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
|
|
||||||
|
object H2Database : LedgerDatabase {
|
||||||
|
override fun getDatabase(server: MinecraftServer) = Database.connect(
|
||||||
|
url = "jdbc:h2:${server.getSavePath(WorldSavePath.ROOT).resolve("ledger.h2").toFile()};MODE=MySQL"
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun getDatabaseIdentifier() = Ledger.identifier("h2")
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package net.quiltservertools.ledger.databases.databases
|
||||||
|
|
||||||
|
import net.minecraft.server.MinecraftServer
|
||||||
|
import net.minecraft.util.Identifier
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
|
|
||||||
|
interface LedgerDatabase {
|
||||||
|
fun getDatabase(server: MinecraftServer): Database
|
||||||
|
fun getDatabaseIdentifier(): Identifier
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package net.quiltservertools.ledger.databases.databases
|
||||||
|
|
||||||
|
import com.github.quiltservertools.ledger.Ledger
|
||||||
|
import net.minecraft.server.MinecraftServer
|
||||||
|
import net.quiltservertools.ledger.databases.DatabaseExtensionSpec
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
|
|
||||||
|
object MySQL : LedgerDatabase {
|
||||||
|
override fun getDatabase(server: MinecraftServer): Database {
|
||||||
|
var url = "jdbc:mysql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true"
|
||||||
|
for (arg in Ledger.config[DatabaseExtensionSpec.properties]) {
|
||||||
|
url = url.plus("&$arg")
|
||||||
|
}
|
||||||
|
return Database.connect(
|
||||||
|
url = url,
|
||||||
|
user = Ledger.config[DatabaseExtensionSpec.userName],
|
||||||
|
password = Ledger.config[DatabaseExtensionSpec.password]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getDatabaseIdentifier() = Ledger.identifier("mysql")
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package net.quiltservertools.ledger.databases.databases
|
||||||
|
|
||||||
|
import com.github.quiltservertools.ledger.Ledger
|
||||||
|
import net.minecraft.server.MinecraftServer
|
||||||
|
import net.quiltservertools.ledger.databases.DatabaseExtensionSpec
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
|
|
||||||
|
object PostgreSQL : LedgerDatabase {
|
||||||
|
override fun getDatabase(server: MinecraftServer): Database {
|
||||||
|
var url = "jdbc:postgresql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true"
|
||||||
|
for (arg in Ledger.config[DatabaseExtensionSpec.properties]) {
|
||||||
|
url = url.plus("&$arg")
|
||||||
|
}
|
||||||
|
return Database.connect(
|
||||||
|
url = url,
|
||||||
|
user = Ledger.config[DatabaseExtensionSpec.userName],
|
||||||
|
password = Ledger.config[DatabaseExtensionSpec.password]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getDatabaseIdentifier() = Ledger.identifier("postgresql")
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package net.quiltservertools.ledger.databases.databases
|
||||||
|
|
||||||
|
import com.github.quiltservertools.ledger.Ledger
|
||||||
|
import net.minecraft.server.MinecraftServer
|
||||||
|
import net.minecraft.util.WorldSavePath
|
||||||
|
import org.jetbrains.exposed.sql.Database
|
||||||
|
import kotlin.io.path.pathString
|
||||||
|
|
||||||
|
object SQLite : LedgerDatabase {
|
||||||
|
override fun getDatabase(server: MinecraftServer) = Database.connect(
|
||||||
|
url = "jdbc:sqlite:${server.getSavePath(WorldSavePath.ROOT).resolve("ledger.sqlite").pathString}"
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun getDatabaseIdentifier() = Ledger.identifier(Ledger.DEFAULT_DATABASE)
|
||||||
|
}
|
@ -8,10 +8,6 @@
|
|||||||
"authors": [
|
"authors": [
|
||||||
"yitzy299"
|
"yitzy299"
|
||||||
],
|
],
|
||||||
"contact": {
|
|
||||||
"homepage": "https://fabricmc.net/",
|
|
||||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
|
||||||
},
|
|
||||||
|
|
||||||
"license": "LGPL-3.0",
|
"license": "LGPL-3.0",
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user