SQLib

SQLib

The easiest way to store data for all your minecraft needs!

by
11.0K Downloads
fabricquiltvelocitylibrarymanagementtechnology
Rent Server with this Mod

About this Mod

Maintenance
PRs Welcome

ko-fi

SQLib

SQLib is the easiest way to store data for all your minecraft needs! A simple sql wrapper made with a focus on minecraft use cases.

Important Note:

This library is not a full-fledged sql wrapper, and does not provide full access to many sql features.
The main focus of this library is to provide an easy and simple way to store data in your mods.
If you are looking for a more advanced database I recommend taking a look at something like Nitrite.

Config

The mod generates a config on first time start that allows you to configure the database used by all mods relying on sqlib.
The default database is a sqlite database running in the sqlib directory.

Datatypes

The datatypes can be accessed via JavaTpes, MinecraftTypes or the AdventureTypes classes. I tend to add support for new types as I run into them in my projects. If you would like one added, pleade make an issue!

Standard Minecraft Adventure
Byte Vec3i Key
Byte[] BlockPos Component
Bool ChunkPos
Short Text
Int Identifier
Float Sound
Double Json
Long NbtElement
String
Char
Date
Color
UUID
URI
URL

You can also add your own custom types as seen here:

Setup

In your build.gradle include:

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

dependencies {
  modImplementation("maven.modrinth:sqlib:3.2.2")
}

Developer Usage

This example uses the built-in database managed by sqlib. for 99% of mods, using the built-in database is good, however
further down are examples for custom database management.

// Do not call SQLib.getDatabase() in a early mod initializer. Doing so will likely crash your mod.
// Calling in or after the regular mod initializer is ok.
Database db = SQLib.getDatabase();

DataStore store = db.dataStore("myModId", "userdata");
        
DataContainer playerData = store.createDataContainer();
playerData.put(JavaTypes.STRING, "username", "CoolGuy123");
playerData.put(MinecraftTypes.BLOCKPOS, "home", new BlockPos(304, 62, 37));
playerData.put(MinecraftTypes.NBT, "nbt", new NbtCompound());

System.out.println(playerdata.get(JavaTypes.STRING, "username"));
System.out.println(playerdata.get(MinecraftTypes.BLOCKPOS, "home"));
System.out.println(playerdata.get(MinecraftTypes.NBT, "nbt"));

Custom Database Management

Postgres db = new Postgres("name", "192.168.1.69", "3306", "cooluser", "radman");
// OR
MySQL db = new MySQL("name", "192.168.1.69", "3306", "cooluser", "radman");
// OR
SQLite db = new SQLite("name", "some/dir");

Transaction Support

This approach will bach sql commands into one command for faster read/writes of large amounts of data.

DataStore store = db.dataStore("modId", "userdata");

DataContainer playerData = table.createDataContainer();
playerData.transaction().put("username", "CoolGuy123").put("home", new BlockPos(304, 62, 37).commit();

Custom Types

You can add a custom type by following the implentations in JavaTypes, MinecraftTypes and AdventureTypes. Then you can use it like any other native SQLib type.

// The SQLPrimitive is the base type to serialize to, and the two function lambdas are to serialize and deserialize from it
public static final SQLibType<JsonElement> JSON = new SQLibType<>(SQLPrimitive.STRING, JsonElement::toString, JsonParser::parseString);

// You can also extend a type like this:
public static final SQLibType<Identifier> IDENTIFIER = new SQLibType<>(SQLPrimitive.STRING, Identifier::toString, Identifier::tryParse);
public static final SQLibType<SoundEvent> SOUND = new SQLibType<>(IDENTIFIER, SoundEvent::getId, SoundEvent::of);

Available Versions

SQLib 3.2.9release
MC 1.16.5, 1.17, 1.17.1, 1.18, 1.18.1, 1.18.2, 1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.20, 1.20.1, 1.20.2, 1.20.3, 1.20.4, 1.20.5, 1.20.6, 1.21, 1.21.1, 1.21.2, 1.21.3, 1.21.4, 1.21.5, 1.21.6, 1.21.7, 1.21.8, 1.21.9, 1.21.10, 1.21.11fabric, quilt, velocity
March 21, 2025
SQLib 3.2.8release
MC 1.16.5, 1.17, 1.17.1, 1.18, 1.18.1, 1.18.2, 1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.20, 1.20.1, 1.20.2, 1.20.3, 1.20.4, 1.20.5, 1.20.6, 1.21, 1.21.1, 1.21.2, 1.21.3, 1.21.4fabric, quilt, velocity
February 5, 2025
SQLib 3.2.5release
MC 1.16.5, 1.17, 1.17.1, 1.18, 1.18.1, 1.18.2, 1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.20, 1.20.1, 1.20.2, 1.20.3, 1.20.4, 1.20.5, 1.20.6, 1.21, 1.21.1, 1.21.2, 1.21.3, 1.21.4fabric, quilt, velocity
December 21, 2024
SQLib 3.2.4release
MC 1.16.5, 1.17, 1.17.1, 1.18, 1.18.1, 1.18.2, 1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.20, 1.20.1, 1.20.2, 1.20.3, 1.20.4, 1.20.5, 1.20.6, 1.21, 1.21.1, 1.21.2, 1.21.3, 1.21.4fabric, quilt, velocity
November 26, 2024
SQLib 3.2.3release
MC 1.16.5, 1.17, 1.17.1, 1.18, 1.18.1, 1.18.2, 1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.20, 1.20.1, 1.20.2, 1.20.3, 1.20.4, 1.20.5, 1.20.6, 1.21, 1.21.1, 1.21.2, 1.21.3fabric, quilt, velocity
October 23, 2024

How to Install SQLib on Your Server

1

Order Server

Order a Minecraft Java server with at least 3 GB RAM (4 GB recommended).

2

Set fabric Loader

In the panel under "Egg", select the fabric loader and matching Minecraft version (1.21.11).

3

Install Mod

Open the mod browser in the dashboard and search for "SQLib". Click "Install" – done! Alternatively, upload the .jar via SFTP to the /mods folder.

Compatibility

Mod Loaders

fabricquiltvelocity

Minecraft Versions

1.21.11, 1.21.10, 1.21.9 (+27 more)

Server-side

~ Optional

Recommended RAM

4 GB(min. 3 GB)

Frequently Asked Questions

SQLib server crashes on startup – what to do?

Most common cause: wrong fabric version or insufficient RAM. Check the server log (latest.log) for "OutOfMemoryError" or "Mixin" errors. With Mado Hosting: ensure at least 3 GB RAM is allocated and the loader matches the mod version (1.21.11). You can switch loaders with one click in the panel.

Is SQLib compatible with fabric and quilt and velocity?

SQLib officially supports fabric, quilt, velocity for Minecraft 1.21.11, 1.21.10, 1.21.9. The Mado dashboard automatically detects incompatible loader combinations.

Server lagging with SQLib – how to optimize performance?

Recommended RAM: 4 GB (per 8 players). Use /spark profiler to check if SQLib consumes the most tick time. Common fixes: reduce server view-distance to 8-10, install "performant" or "starlight" as supplementary mods on Forge. With Mado Hosting, your server runs on NVMe SSDs with dedicated CPU cores for minimal latency.

Rent Modded Server

Install SQLib with just one click on your server.

Recommended RAM
4 GBab €8/mo
Min. 3 GB | +1 GB pro 8 Spieler
Create Server Now
1-Click Mod Install
NVMe SSD Storage
DDoS Protection included

Details

License
Creative Commons Zero v1.0 Universal
Server-side
Optional

Supported Versions

1.21.111.21.101.21.91.21.81.21.71.21.61.21.51.21.41.21.31.21.2+20 more