Skip to content
Ethan Stevenson edited this page Sep 1, 2021 · 2 revisions

Setup

The library first needs to be included into your project. The simplest way to do this is through Jitpack. In you build.gradle make sure to include:

repositories {
    maven { url 'https://jitpack.io' }
}

And

dependencies {
  modImplementation 'com.github.MrNavaStar:SQLib:v1.0.0'
  
  //Or if you wish to include with the mod:
  include(modImplementation('com.github.MrNavaStar:SQLib:v1.0.0'))
}

Usage

The database must first be setup to use either sqlite or mysql like so:

  • SQLITE
Database.TYPE = SqlTypes.SQLITE;
Database.DATABASE_NAME = "MyAmazingDatabase";
Database.SQLITE_DIRECTORY = "/database/folder";

Database.init();
  • MYSQL
Database.TYPE = SqlTypes.MYSQL;
Database.DATABASE_NAME = "MyAmazingDatabase";
Database.MYSQL_ADDRESS = "127.0.0.1";
Database.MYSQL_PORT = "3306";
Database.MYSQL_USERNAME = "MrNavaStar";
Database.MYSQL_PASSWORD = "123456";

Database.init();

Now a table can be added to store data. This table will automatically be added to the database (Note that it is not required to include your mod id in the table name, however doing so will result in less conflict with other mods that name their tables the same):

Table playerData = new Table(MODID + "PlayerData");

In order to store data in the table you need a DataContainer object. This will simply provide a way to handle your data in an object orientied manner:

DataContainer player = new DataContainer(playerUuid);
playerData.put(player);

Finally, you can use the DataContainer to put, get, and drop data:

player.put("NickName", "Bob Ross");
player.put("Health", 100);

String name = player.getString("NickName");
String health = player.getInt("Health");

player.dropString("NickName");
player.dropInt("Health");
Clone this wiki locally