Skip to content

Commit 03d45ac

Browse files
committed
docs: update README
1 parent 391264d commit 03d45ac

File tree

2 files changed

+190
-54
lines changed

2 files changed

+190
-54
lines changed

README.md

Lines changed: 33 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
# JOOQConnector
2+
A library for working with databases using JOOQ ORM for Java.
23

3-
[![License: GNU GPLv3](https://img.shields.io/badge/License-%20%20GNU%20GPLv3%20-yellow)](LICENSE)
4+
[![License: GNU GPLv3](https://img.shields.io/badge/License-GNU%20GPLv3-yellow)](LICENSE)
45
[![Version](https://img.shields.io/badge/Version-1.0.1-brightgreen)](https://github.com/MEFRREEX/JOOQConnector/releases/tag/1.0.1)
56
[![Jitpack](https://jitpack.io/v/MEFRREEX/JOOQConnector.svg)](https://jitpack.io/#MEFRREEX/JOOQConnector)
67

7-
## 🤔 About
8-
Library for working with database using JOOQ
8+
## 📖 Overview
9+
**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.
910

10-
Features:
11-
- SQLite3 support
12-
- MySQL support
13-
- Disabled printing logo and tips from JOOQ
14-
- Inclusion of JOOQ, SQLite and MySQL drivers in jar file
15-
- Support for different server software (Bukkit, Nukkit, PowerNukkitX, JukeboxMC, WaterdogPE)
11+
### ✨ Features
12+
- **SQLite3 and MySQL Support**: Seamless integration with SQLite and MySQL databases.
13+
- **No Unnecessary Logs**: Disable JOOQ logo and tips from appearing in the logs.
14+
- **Bundled Drivers**: Includes SQLite, and MySQL drivers in the JAR.
15+
- **Cross-Platform Support**: Compatible with different Minecraft server software.
1616

17-
## 🛠 Examples
17+
## 🛠 Code Examples
1818

19-
If you are using a standalone api, you can disable the printing of logo and tips when you run the program
19+
### Disable JOOQ Logs
20+
You can disable the printing of the JOOQ logo and tips:
2021
```java
2122
JOOQConnector.setJOOQMessagesEnabled(false);
2223
```
2324

24-
Example of using SQLite3 database
25+
### SQLite3 Example
2526
```java
2627
Table<?> table = DSL.table("test");
2728
SQLiteDatabase database = new SQLiteDatabase(new File("database.db"));
@@ -32,7 +33,7 @@ database.getConnection().thenAcceptAsync(connection -> {
3233
.createTableIfNotExists(table)
3334
.column("id", SQLDataType.INTEGER)
3435
.column("data", SQLDataType.VARCHAR)
35-
.unique("id") // Value of this column will be unique
36+
.unique("id")
3637
.execute();
3738
}).join();
3839

@@ -50,32 +51,27 @@ String value = database.getConnection().thenApplyAsync(connection -> {
5051
.from(table)
5152
.where(DSL.field("id").eq(1))
5253
.fetch();
53-
54-
if (!result.isEmpty()) {
55-
// Get the value with index 0
56-
return result.get(0).get(DSL.field("data", String.class));
57-
}
58-
return null;
54+
return result.isEmpty() ? null : result.get(0).get(DSL.field("data", String.class));
5955
}).join();
6056

6157
System.out.println("Value from table: " + value);
6258
```
6359

64-
Example of using a MySQL database
60+
### MySQL Example
6561
```java
6662
MySQLDatabase database = new MySQLDatabase("127.0.0.1:3306", "database", "user", "password");
6763

68-
// Other code will be identical...
64+
// The rest of the code is identical to the SQLite example...
6965
```
7066

71-
Example of using SQlite or MySQL database
67+
### Switching Between SQLite and MySQL
7268
```java
7369
IDatabase database = sqlite ?
7470
new SQLiteDatabase(new File("database.db")) :
7571
new MySQLDatabase("127.0.0.1:3306", "database", "user", "password");
7672
```
7773

78-
You can make a separate class with methods for the database
74+
### Organizing Database Operations in a Class
7975
```java
8076
public class Database {
8177

@@ -91,7 +87,7 @@ public class Database {
9187
.createTableIfNotExists(table)
9288
.column("id", SQLDataType.INTEGER)
9389
.column("data", SQLDataType.VARCHAR)
94-
.unique("id") // Value of this column will be unique
90+
.unique("id")
9591
.execute();
9692
}).join();
9793
}
@@ -109,51 +105,31 @@ public class Database {
109105
return database.getConnection().thenApplyAsync(connection -> {
110106
Result<Record> result = DSL.using(connection).select()
111107
.from(table)
112-
.where(DSL.field("id").eq(1))
108+
.where(DSL.field("id").eq(id))
113109
.fetch();
114110

115-
if (!result.isEmpty()) {
116-
// Get the value with index 0
117-
return result.get(0).get(DSL.field("data", String.class));
118-
}
119-
return null;
111+
return result.isEmpty() ? null : result.get(0).get(DSL.field("data", String.class));
120112
});
121113
}
122-
123-
public static void main(String[] args) {
124-
Database database = new Database(
125-
new SQLiteDatabase(new File("database.db")),
126-
DSL.table("test")
127-
);
128-
129-
// Inserting value into the table
130-
database.addValue(1, "Test string").join();
131-
132-
// Getting value from the table
133-
String value = database.getValue(1).join();
134-
System.out.println("Value from table: " + value);
135-
}
136114
}
137115
```
138116

139117
## 🔌 Installation
140118

141-
If you are not using the standalone api version place the plugin of the appropriate version (for your software) in the `plugins` folder.
142-
119+
### Plugin Setup
120+
If you're not using the standalone API version, place the plugin JAR in your server's `plugins` folder.
143121

144122
### Maven
123+
Add the following repository and dependency to your `pom.xml`:
145124

146-
Repository:
147125
```xml
148126
<repositories>
149127
<repository>
150128
<id>jitpack.io</id>
151129
<url>https://jitpack.io</url>
152130
</repository>
153131
</repositories>
154-
```
155-
Dependency:
156-
```xml
132+
157133
<dependency>
158134
<groupId>com.github.MEFRREEX</groupId>
159135
<artifactId>JOOQConnector</artifactId>
@@ -163,16 +139,19 @@ Dependency:
163139
```
164140

165141
### Gradle
166-
Repository:
142+
Add the following repository and dependency to your `build.gradle`:
143+
167144
```groovy
168145
repositories {
169146
mavenCentral()
170147
maven { url 'https://jitpack.io' }
171148
}
172-
```
173-
Dependency:
174-
```groovy
149+
175150
dependencies {
176151
implementation 'com.github.MEFRREEX:JOOQConnector:1.0.1'
177152
}
178153
```
154+
155+
___
156+
157+
[Switch to Russian](README_ru.md)

README_ru.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# JOOQConnector
2+
Библиотека для работы с базами данных с использованием ORM JOOQ для Java.
3+
4+
[![Лицензия: GNU GPLv3](https://img.shields.io/badge/License-GNU%20GPLv3-yellow)](LICENSE)
5+
[![Версия](https://img.shields.io/badge/Version-1.0.1-brightgreen)](https://github.com/MEFRREEX/JOOQConnector/releases/tag/1.0.1)
6+
[![Jitpack](https://jitpack.io/v/MEFRREEX/JOOQConnector.svg)](https://jitpack.io/#MEFRREEX/JOOQConnector)
7+
8+
## 📖 Обзор
9+
**JOOQConnector** — это библиотека для Java, предназначенная для удобной работы с базами данных через ORM JOOQ. Она поддерживает SQLite и MySQL, а также рассчитана для работы с различными серверными ядрами, таких как Bukkit, Nukkit, PowerNukkitX, JukeboxMC и WaterdogPE.
10+
11+
### ✨ Возможности
12+
- **Поддержка SQLite3 и MySQL**: Бесшовная интеграция с базами данных SQLite и MySQL.
13+
- **Отключение логов**: Возможность отключить вывод логотипа и подсказок JOOQ в логах.
14+
- **Встроенные драйверы**: Включает драйверы SQLite и MySQL в JAR-файл.
15+
- **Кроссплатформенная поддержка**: Совместимость с различными программными серверами Minecraft.
16+
17+
## 🛠 Примеры кода
18+
19+
### Отключение логов JOOQ
20+
Вы можете отключить вывод логотипа и подсказок JOOQ:
21+
```java
22+
JOOQConnector.setJOOQMessagesEnabled(false);
23+
```
24+
25+
### Пример работы с SQLite3
26+
```java
27+
Table<?> table = DSL.table("test");
28+
SQLiteDatabase database = new SQLiteDatabase(new File("database.db"));
29+
30+
// Создание таблицы
31+
database.getConnection().thenAcceptAsync(connection -> {
32+
DSL.using(connection)
33+
.createTableIfNotExists(table)
34+
.column("id", SQLDataType.INTEGER)
35+
.column("data", SQLDataType.VARCHAR)
36+
.unique("id")
37+
.execute();
38+
}).join();
39+
40+
// Вставка значения
41+
database.getConnection().thenAcceptAsync(connection -> {
42+
DSL.using(connection).insertInto(table)
43+
.set(DSL.field("id"), 1)
44+
.set(DSL.field("data"), "Test string")
45+
.execute();
46+
}).join();
47+
48+
// Получение значения
49+
String value = database.getConnection().thenApplyAsync(connection -> {
50+
Result<Record> result = DSL.using(connection).select()
51+
.from(table)
52+
.where(DSL.field("id").eq(1))
53+
.fetch();
54+
return result.isEmpty() ? null : result.get(0).get(DSL.field("data", String.class));
55+
}).join();
56+
57+
System.out.println("Value from table: " + value);
58+
```
59+
60+
### Пример работы с MySQL
61+
```java
62+
MySQLDatabase database = new MySQLDatabase("127.0.0.1:3306", "database", "user", "password");
63+
64+
// Остальной код идентичен примеру с SQLite...
65+
```
66+
67+
### Переключение между SQLite и MySQL
68+
```java
69+
IDatabase database = sqlite ?
70+
new SQLiteDatabase(new File("database.db")) :
71+
new MySQLDatabase("127.0.0.1:3306", "database", "user", "password");
72+
```
73+
74+
### Организация операций с базой данных в классе
75+
```java
76+
public class Database {
77+
78+
private final IDatabase database;
79+
private final Table<?> table;
80+
81+
public Database(IDatabase database, Table<?> table) {
82+
this.database = database;
83+
this.table = table;
84+
85+
database.getConnection().thenAcceptAsync(connection -> {
86+
DSL.using(connection)
87+
.createTableIfNotExists(table)
88+
.column("id", SQLDataType.INTEGER)
89+
.column("data", SQLDataType.VARCHAR)
90+
.unique("id")
91+
.execute();
92+
}).join();
93+
}
94+
95+
public CompletableFuture<Void> addValue(int id, String data) {
96+
return database.getConnection().thenAcceptAsync(connection -> {
97+
DSL.using(connection).insertInto(table)
98+
.set(DSL.field("id"), id)
99+
.set(DSL.field("data"), data)
100+
.execute();
101+
});
102+
}
103+
104+
public CompletableFuture<String> getValue(int id) {
105+
return database.getConnection().thenApplyAsync(connection -> {
106+
Result<Record> result = DSL.using(connection).select()
107+
.from(table)
108+
.where(DSL.field("id").eq(id))
109+
.fetch();
110+
111+
return result.isEmpty() ? null : result.get(0).get(DSL.field("data", String.class));
112+
});
113+
}
114+
}
115+
```
116+
117+
## 🔌 Установка
118+
119+
### Установка плагина
120+
Если вы не используете версию API для самостоятельного использования, поместите JAR-файл плагина в папку `plugins` вашего сервера.
121+
122+
### Maven
123+
Добавьте следующий репозиторий и зависимость в ваш `pom.xml`:
124+
125+
```xml
126+
<repositories>
127+
<repository>
128+
<id>jitpack.io</id>
129+
<url>https://jitpack.io</url>
130+
</repository>
131+
</repositories>
132+
133+
<dependency>
134+
<groupId>com.github.MEFRREEX</groupId>
135+
<artifactId>JOOQConnector</artifactId>
136+
<version>1.0.1</version>
137+
<scope>provided</scope>
138+
</dependency>
139+
```
140+
141+
### Gradle
142+
Добавьте следующий репозиторий и зависимость в ваш `build.gradle`:
143+
144+
```groovy
145+
repositories {
146+
mavenCentral()
147+
maven { url 'https://jitpack.io' }
148+
}
149+
150+
dependencies {
151+
implementation 'com.github.MEFRREEX:JOOQConnector:1.0.1'
152+
}
153+
```
154+
155+
___
156+
157+
[Переключиться на английский](README.md)

0 commit comments

Comments
 (0)