Skip to content

Commit 9c887cd

Browse files
Merge pull request #13 from jjurek98/testing-mariadb
2 parents 0776be6 + 971c319 commit 9c887cd

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Ledger Databases
22

3-
Adds support for MySQL, H2, and PostgreSQL databases in Ledger
3+
Adds support for MySQL, MariaDB, H2, and PostgreSQL databases in Ledger
44

55
## Use
66

77
## Common
88

9-
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
9+
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
1010

1111
## H2
1212

@@ -34,6 +34,23 @@ connectionTimeout = 60000
3434

3535
`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`
3636

37+
## MariaDB
38+
39+
Add the following to the bottom of your Ledger config file:
40+
41+
```toml
42+
[database_extensions]
43+
database = "MARIADB"
44+
url = ""
45+
username = ""
46+
password = ""
47+
properties = []
48+
maxPoolSize = 10
49+
connectionTimeout = 60000
50+
```
51+
52+
`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`
53+
3754
## PostgreSQL
3855

3956
```toml

build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'fabric-loom' version '1.2.+'
2+
id 'fabric-loom' version '1.6.+'
33
id 'maven-publish'
44
id 'org.jetbrains.kotlin.jvm' version "1.8.22"
55
}
@@ -40,6 +40,9 @@ dependencies {
4040
// MySQL
4141
implementation(include('com.mysql:mysql-connector-j:8.3.0'))
4242

43+
// MariaDB
44+
implementation(include('org.mariadb.jdbc:mariadb-java-client:3.3.3'))
45+
4346
// PostgreSQL
4447
implementation(include("org.postgresql:postgresql:42.7.3"))
4548
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package net.quiltservertools.ledger.databases
33
import net.quiltservertools.ledger.databases.databases.H2Database
44
import net.quiltservertools.ledger.databases.databases.LedgerDatabase
55
import net.quiltservertools.ledger.databases.databases.MySQL
6+
import net.quiltservertools.ledger.databases.databases.MariaDB
67
import net.quiltservertools.ledger.databases.databases.PostgreSQL
78
import net.quiltservertools.ledger.databases.databases.SQLite
89

@@ -11,5 +12,6 @@ enum class Databases(val database: LedgerDatabase) {
1112
MYSQL(MySQL),
1213
H2(H2Database),
1314
POSTGRESQL(PostgreSQL),
14-
SQLITE(SQLite)
15-
}
15+
SQLITE(SQLite),
16+
MARIADB(MariaDB)
17+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package net.quiltservertools.ledger.databases.databases
2+
3+
import com.github.quiltservertools.ledger.Ledger
4+
import com.zaxxer.hikari.HikariConfig
5+
import com.zaxxer.hikari.HikariDataSource
6+
import net.quiltservertools.ledger.databases.DatabaseExtensionSpec
7+
import net.quiltservertools.ledger.databases.LedgerDatabases
8+
import java.nio.file.Path
9+
import javax.sql.DataSource
10+
11+
object MariaDB : LedgerDatabase {
12+
override fun getDataSource(savePath: Path): DataSource = HikariDataSource(HikariConfig().apply {
13+
jdbcUrl = "jdbc:mariadb://${Ledger.config[DatabaseExtensionSpec.url]}"
14+
username = Ledger.config[DatabaseExtensionSpec.userName]
15+
password = Ledger.config[DatabaseExtensionSpec.password]
16+
maximumPoolSize = Ledger.config[DatabaseExtensionSpec.maxPoolSize]
17+
connectionTimeout = Ledger.config[DatabaseExtensionSpec.connectionTimeout]
18+
addDataSourceProperty("rewriteBatchedStatements", "true")
19+
addDataSourceProperty("cachePrepStmts", true)
20+
addDataSourceProperty("prepStmtCacheSize", 250)
21+
addDataSourceProperty("prepStmtCacheSqlLimit", 2048)
22+
addDataSourceProperty("useServerPrepStmts", true)
23+
addDataSourceProperty("cacheCallableStmts", true)
24+
addDataSourceProperty("cacheResultSetMetadata", true)
25+
addDataSourceProperty("cacheServerConfiguration", true)
26+
addDataSourceProperty("useLocalSessionState", true)
27+
addDataSourceProperty("elideSetAutoCommits", true)
28+
addDataSourceProperty("alwaysSendSetIsolation", false)
29+
addDataSourceProperty("useJDBCCompliantTimezoneShift", true)
30+
addDataSourceProperty("useLegacyDatetimeCode", false)
31+
addDataSourceProperty("serverTimezone", "UTC")
32+
for ((key, value) in Ledger.config[DatabaseExtensionSpec.properties]) {
33+
addDataSourceProperty(key, value)
34+
}
35+
})
36+
37+
override fun getDatabaseIdentifier() = LedgerDatabases.identifier("mariadb")
38+
}

0 commit comments

Comments
 (0)