https://github.com/mefrreex/jooqconnector
A library for working with databases using JOOQ ORM for Java
https://github.com/mefrreex/jooqconnector
database mysql sqlite sqlite3
Last synced: 11 months ago
JSON representation
A library for working with databases using JOOQ ORM for Java
- Host: GitHub
- URL: https://github.com/mefrreex/jooqconnector
- Owner: MEFRREEX
- License: gpl-3.0
- Created: 2024-04-22T09:52:19.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-04T23:56:48.000Z (over 1 year ago)
- Last Synced: 2025-03-29T23:22:09.310Z (over 1 year ago)
- Topics: database, mysql, sqlite, sqlite3
- Language: Java
- Homepage:
- Size: 99.6 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JOOQConnector
A library for working with databases using JOOQ ORM for Java.
[](LICENSE)
[](https://github.com/MEFRREEX/JOOQConnector/releases/tag/1.0.1)
[](https://jitpack.io/#MEFRREEX/JOOQConnector)
## 📖 Overview
**JOOQConnector** is a Java library designed for easy interaction with databases using the JOOQ ORM. It includes built-in support for SQLite and MySQL databases and is designed to work with various server software like Bukkit, Nukkit, PowerNukkitX, JukeboxMC, and WaterdogPE.
### ✨ Features
- **SQLite3 and MySQL Support**: Seamless integration with SQLite and MySQL databases.
- **No Unnecessary Logs**: Disable JOOQ logo and tips from appearing in the logs.
- **Bundled Drivers**: Includes SQLite, and MySQL drivers in the JAR.
- **Cross-Platform Support**: Compatible with different Minecraft server software.
## 🛠Code Examples
### Disable JOOQ Logs
You can disable the printing of the JOOQ logo and tips:
```java
JOOQConnector.setJOOQMessagesEnabled(false);
```
### SQLite3 Example
```java
Table> table = DSL.table("test");
SQLiteDatabase database = new SQLiteDatabase(new File("database.db"));
// Creating table
database.getConnection().thenAcceptAsync(connection -> {
DSL.using(connection)
.createTableIfNotExists(table)
.column("id", SQLDataType.INTEGER)
.column("data", SQLDataType.VARCHAR)
.unique("id")
.execute();
}).join();
// Inserting value into the table
database.getConnection().thenAcceptAsync(connection -> {
DSL.using(connection).insertInto(table)
.set(DSL.field("id"), 1)
.set(DSL.field("data"), "Test string")
.execute();
}).join();
// Getting value from the table
String value = database.getConnection().thenApplyAsync(connection -> {
Result result = DSL.using(connection).select()
.from(table)
.where(DSL.field("id").eq(1))
.fetch();
return result.isEmpty() ? null : result.get(0).get(DSL.field("data", String.class));
}).join();
System.out.println("Value from table: " + value);
```
### MySQL Example
```java
MySQLDatabase database = new MySQLDatabase("127.0.0.1:3306", "database", "user", "password");
// The rest of the code is identical to the SQLite example...
```
### Switching Between SQLite and MySQL
```java
IDatabase database = sqlite ?
new SQLiteDatabase(new File("database.db")) :
new MySQLDatabase("127.0.0.1:3306", "database", "user", "password");
```
### Organizing Database Operations in a Class
```java
public class Database {
private final IDatabase database;
private final Table> table;
public Database(IDatabase database, Table> table) {
this.database = database;
this.table = table;
database.getConnection().thenAcceptAsync(connection -> {
DSL.using(connection)
.createTableIfNotExists(table)
.column("id", SQLDataType.INTEGER)
.column("data", SQLDataType.VARCHAR)
.unique("id")
.execute();
}).join();
}
public CompletableFuture addValue(int id, String data) {
return database.getConnection().thenAcceptAsync(connection -> {
DSL.using(connection).insertInto(table)
.set(DSL.field("id"), id)
.set(DSL.field("data"), data)
.execute();
});
}
public CompletableFuture getValue(int id) {
return database.getConnection().thenApplyAsync(connection -> {
Result result = DSL.using(connection).select()
.from(table)
.where(DSL.field("id").eq(id))
.fetch();
return result.isEmpty() ? null : result.get(0).get(DSL.field("data", String.class));
});
}
}
```
## 🔌 Installation
### Plugin Setup
If you're not using the standalone API version, place the plugin JAR in your server's `plugins` folder.
### Maven
Add the following repository and dependency to your `pom.xml`:
```xml
jitpack.io
https://jitpack.io
com.github.MEFRREEX
JOOQConnector
1.0.1
provided
```
### Gradle
Add the following repository and dependency to your `build.gradle`:
```groovy
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.MEFRREEX:JOOQConnector:1.0.1'
}
```
___
[Switch to Russian](README_ru.md)