Skip to content

Commit

Permalink
fix mysql/mariadb
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNavaStar committed Nov 25, 2023
1 parent 9c2ee09 commit 8f6ad17
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ jobs:
java: 17
game-versions: |
>=1.16.5
dependencies: |
fabric-api
22 changes: 13 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// SQL Drivers
shadow implementation("org.xerial:sqlite-jdbc:${project.sqlite_version}")
shadow implementation("mysql:mysql-connector-java:${project.mysql_version}")
//Config
shadow implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:${project.jackson_version}")
implementation("org.xerial:sqlite-jdbc:${project.sqlite_version}")
implementation("org.mariadb.jdbc:mariadb-java-client:${project.mariadb_version}")
// Config
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:${project.jackson_version}")

// Extra
compileOnly "org.projectlombok:lombok:1.18.28"
Expand All @@ -31,13 +31,17 @@ dependencies {

shadowJar {
archiveBaseName.set('sqlib')
configurations = [project.configurations.shadow]

minimize {
exclude(dependency("org.xerial:sqlite-jdbc:.*"))
exclude(dependency("mysql:mysql-connector-java:.*"))
dependencies {
mergeServiceFiles()
include(dependency("org.xerial:sqlite-jdbc:.*"))
include(dependency("org.mariadb.jdbc:mariadb-java-client:.*"))
// Jackson Pain
include(dependency("com.fasterxml.jackson.core:jackson-annotations:.*"))
include(dependency("com.fasterxml.jackson.core:jackson-core:.*"))
include(dependency("com.fasterxml.jackson.core:jackson-databind:.*"))
include(dependency("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:.*"))
}
minimize()
}

jar.finalizedBy('shadowJar')
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ archives_base_name=sqlib
sqlite_version=3.44.0.0
# https://mvnrepository.com/artifact/mysql/mysql-connector-java
mysql_version=8.0.33
# https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client
mariadb_version=3.3.0
# https://github.com/FasterXML/jackson-dataformats-text
jackson_version=2.15.3
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,4 @@ public Properties getConnectionProperties() {
properties.put("password", password);
return properties;
}

@Override
public void beginTransaction() {
sqlConnection.beginTransaction(false);
}
}
}
6 changes: 5 additions & 1 deletion src/main/java/me/mrnavastar/sqlib/database/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public void close() {
sqlConnection = null;
}

public abstract void beginTransaction();
public abstract String getTransactionString();

public void beginTransaction() {
sqlConnection.beginTransaction(getTransactionString());
};

public void endTransaction() {
sqlConnection.endTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ public MySQLDatabase(String name, String address, String port, String username,

@Override
public String getConnectionUrl() {
return "jdbc:mysql://" + address + ":" + port + "/" + name;
return "jdbc:mariadb://" + address + ":" + port + "/" + name;
}

@Override
public String getTableCreationQuery(String tableName, String columns, boolean autoIncrementId) {
if (autoIncrementId) return "CREATE TABLE IF NOT EXISTS %s (ID int, %s, PRIMARY KEY (ID) AUTO_INCREMENT);".formatted(tableName, columns);
return "CREATE TABLE IF NOT EXISTS %s (ID TEXT, %s, PRIMARY KEY (ID(256)));".formatted(tableName, columns);
}

@Override
public String getTransactionString() {
return "BEGIN;";
}
}
10 changes: 5 additions & 5 deletions src/main/java/me/mrnavastar/sqlib/database/SQLiteDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public String getTableCreationQuery(String tableName, String columns, boolean au
return "CREATE TABLE IF NOT EXISTS %s (%s, ID MEDIUMTEXT PRIMARY KEY);".formatted(tableName, columns);
}

@Override
public String getTransactionString() {
return "BEGIN EXCLUSIVE;";
}

public void setMode(@NonNull Mode mode) {
this.mode = mode;
executeCommand("PRAGMA journal_mode = %s;".formatted(mode), true);
}

@Override
public void beginTransaction() {
sqlConnection.beginTransaction(true);
}
}
4 changes: 2 additions & 2 deletions src/main/java/me/mrnavastar/sqlib/sql/SQLConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public PreparedStatement executeCommand(String sql, boolean autoClose, Object...
}
}

public void beginTransaction(boolean exclusive) {
executeCommand((exclusive) ? "BEGIN;" : "BEGIN EXCLUSIVE;", true);
public void beginTransaction(String transactionString) {
executeCommand(transactionString, true);
}

public void endTransaction() {
Expand Down

0 comments on commit 8f6ad17

Please sign in to comment.