Merge pull request #13 from jjurek98/testing-mariadb

This commit is contained in:
Will 2024-06-27 13:38:30 -07:00 committed by GitHub
commit 9c887cda5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 65 additions and 5 deletions

View File

@ -1,12 +1,12 @@
# Ledger Databases # Ledger Databases
Adds support for MySQL, H2, and PostgreSQL databases in Ledger Adds support for MySQL, MariaDB, H2, and PostgreSQL databases in Ledger
## Use ## Use
## Common ## Common
For both MySQL, H2, and PostgreSQL, you will need to place Ledger Databases in your mods folder along with Ledger 1.1.0 or newer For both MySQL, MariaDB, H2, and PostgreSQL, you will need to place Ledger Databases in your mods folder along with Ledger 1.1.0 or newer
## H2 ## H2
@ -34,6 +34,23 @@ connectionTimeout = 60000
`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`
## MariaDB
Add the following to the bottom of your Ledger config file:
```toml
[database_extensions]
database = "MARIADB"
url = ""
username = ""
password = ""
properties = []
maxPoolSize = 10
connectionTimeout = 60000
```
`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 ## PostgreSQL
```toml ```toml

View File

@ -1,5 +1,5 @@
plugins { plugins {
id 'fabric-loom' version '1.2.+' id 'fabric-loom' version '1.6.+'
id 'maven-publish' id 'maven-publish'
id 'org.jetbrains.kotlin.jvm' version "1.8.22" id 'org.jetbrains.kotlin.jvm' version "1.8.22"
} }
@ -40,6 +40,9 @@ dependencies {
// MySQL // MySQL
implementation(include('com.mysql:mysql-connector-j:8.3.0')) implementation(include('com.mysql:mysql-connector-j:8.3.0'))
// MariaDB
implementation(include('org.mariadb.jdbc:mariadb-java-client:3.3.3'))
// PostgreSQL // PostgreSQL
implementation(include("org.postgresql:postgresql:42.7.3")) implementation(include("org.postgresql:postgresql:42.7.3"))
} }

View File

@ -3,6 +3,7 @@ package net.quiltservertools.ledger.databases
import net.quiltservertools.ledger.databases.databases.H2Database import net.quiltservertools.ledger.databases.databases.H2Database
import net.quiltservertools.ledger.databases.databases.LedgerDatabase import net.quiltservertools.ledger.databases.databases.LedgerDatabase
import net.quiltservertools.ledger.databases.databases.MySQL import net.quiltservertools.ledger.databases.databases.MySQL
import net.quiltservertools.ledger.databases.databases.MariaDB
import net.quiltservertools.ledger.databases.databases.PostgreSQL import net.quiltservertools.ledger.databases.databases.PostgreSQL
import net.quiltservertools.ledger.databases.databases.SQLite import net.quiltservertools.ledger.databases.databases.SQLite
@ -11,5 +12,6 @@ enum class Databases(val database: LedgerDatabase) {
MYSQL(MySQL), MYSQL(MySQL),
H2(H2Database), H2(H2Database),
POSTGRESQL(PostgreSQL), POSTGRESQL(PostgreSQL),
SQLITE(SQLite) SQLITE(SQLite),
MARIADB(MariaDB)
} }

View File

@ -0,0 +1,38 @@
package net.quiltservertools.ledger.databases.databases
import com.github.quiltservertools.ledger.Ledger
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import net.quiltservertools.ledger.databases.DatabaseExtensionSpec
import net.quiltservertools.ledger.databases.LedgerDatabases
import java.nio.file.Path
import javax.sql.DataSource
object MariaDB : LedgerDatabase {
override fun getDataSource(savePath: Path): DataSource = HikariDataSource(HikariConfig().apply {
jdbcUrl = "jdbc:mariadb://${Ledger.config[DatabaseExtensionSpec.url]}"
username = Ledger.config[DatabaseExtensionSpec.userName]
password = Ledger.config[DatabaseExtensionSpec.password]
maximumPoolSize = Ledger.config[DatabaseExtensionSpec.maxPoolSize]
connectionTimeout = Ledger.config[DatabaseExtensionSpec.connectionTimeout]
addDataSourceProperty("rewriteBatchedStatements", "true")
addDataSourceProperty("cachePrepStmts", true)
addDataSourceProperty("prepStmtCacheSize", 250)
addDataSourceProperty("prepStmtCacheSqlLimit", 2048)
addDataSourceProperty("useServerPrepStmts", true)
addDataSourceProperty("cacheCallableStmts", true)
addDataSourceProperty("cacheResultSetMetadata", true)
addDataSourceProperty("cacheServerConfiguration", true)
addDataSourceProperty("useLocalSessionState", true)
addDataSourceProperty("elideSetAutoCommits", true)
addDataSourceProperty("alwaysSendSetIsolation", false)
addDataSourceProperty("useJDBCCompliantTimezoneShift", true)
addDataSourceProperty("useLegacyDatetimeCode", false)
addDataSourceProperty("serverTimezone", "UTC")
for ((key, value) in Ledger.config[DatabaseExtensionSpec.properties]) {
addDataSourceProperty(key, value)
}
})
override fun getDatabaseIdentifier() = LedgerDatabases.identifier("mariadb")
}