Перейти к содержимому

Database Utils

Простой мод для разработчиков, упрощающий работу с базой данных

Fabric
Загрузчики
Fabric
Скачиваний на Modrinth
281
Подписчиков на Modrinth
2
версии
2
Обновлён
14 июля 202614 июл.
Опубликован
в 2025
Это библиотека — она нужна другим модам и сама ничего не добавляет в игруНужна 1 модам. Скачайте её, если этого требует другой мод.

Коротко о моде

Библиотека — нужна другим модам: её требуют 1
Работает на Fabric
Для Minecraft 1.20–26.2
Работает и в игре, и на сервере — ставьте, где нужен
Последняя версия — 1.0.0+26.1 от 14 июля 2026
Лицензия MIT — бесплатно
Где нужен
В игренеобязателенНа серверенеобязателен

Работает и в игре, и на сервере — ставьте, где нужен

Версии игры1.20–26.2
Оригинал на английскомПоказать перевод

Database Utils


🔎 Explanations

This mod includes some utilities for working with databases.
The most popular connectors are included directly in the mod JAR, which avoids having to import them into each mod and helps reduce the overall size of your projects.

To import this library, you must add the following to your build.gradle file.

repositories {
    maven { url "https://api.modrinth.com/maven" }
}

dependencies {
    implementation "maven.modrinth:database-utils:1.0.0"
}

🖥️ Usage

Configuration is managed by this library. By using the following line, a .properties file is automatically created (if it does not already exist) and loaded from the config folder.

Config config = new Config(MOD_ID);

In this example, the file will be named MOD_ID.properties.
Here is an example configuration file.

storage=postgres
host=127.0.0.1
port=5432
database=minecraft_db
user=user
password=password
KeyDescription
storageDatabase type. Must be one of: postgres, mysql, mariadb, sqlite, or test.
hostIP address or hostname of the database server
portPort used by the database server.
databaseName of the database.
userUser used to connect to the database.
passwordPassword of the user.

Then, you need to define your own class MyCustomDB, which extends DatabaseQueries.
This class is intended to contain all SQL related methods. In this context, you have access to some method from DatabaseQueries, such as getType, which help you create an implementation compatible with multiple databases.

public class MyCustomDB extends DatabaseQueries {

    public MyCustomDB(Database db) {
        super(db);
    }
    
    @Override
    public void init() {
        try (Connection connection = getConnection()) {
            /* ... */
        } catch (SQLException | DatabaseLinkException e) {
            LOGGER.error("Unable to initialize: {}", e.getMessage());
        }
    }
    
    /* other methods */
    
    public void someMethod() {
        /* ... */
    }
}

You will also need to create a database instance. This is where the Config object is used. The following code snippet retrieves the database defined in the configuration and initializes your DatabaseQueries implementation.

Database database = DatabaseUtils.getDatabase(config);
MyCustomDB custom = new MyCustomDB(database);

You can now call any query defined in your DatabaseQueries implementation through your custom instance.

custom.someMethod();

Частые вопросы

Как установить Database Utils?

Установите Fabric под свою версию Minecraft, скачайте Database Utils под ту же версию и загрузчик, положите файл в папку mods и запустите игру с профилем загрузчика.

Для каких версий Minecraft есть Database Utils?

У Database Utils есть сборки для Minecraft 1.20–26.2.

Нужен ли Database Utils на сервере?

Работает и в игре, и на сервере — ставьте, где нужен

Лицензия и источник
MIT Licenseможно свободно использовать и распространять с указанием автора
Оригинал — Modrinth↗Файлы — без изменений, проверены по SHA-512Это ваш мод? Правообладателям

Сайт использует cookie: необходимые — для входа и темы, а также счётчики посещений Яндекс Метрика и LiveInternet — по ним мы видим, как пользуются сайтом. Рекламных cookie у нас нет. Подробнее