abyssallib-docs Help

Database

The library adds an easy to use api for database management for plugins, currently MySQL and SQLite are supported, more may be added later on.

YOU MUST HAVE SOME EXPERIENCE WITH DATABASES!

Choose and create a Database instance:

File file = new File(getDataFolder(), "data.db"); Database db = new SqliteDatabase(file);
Database db = new MysqlDatabase("host", port, "database", "user", "password");

Connecting and disconnecting:

db.connect(); // Opens the connection db.disconnect(); // Safely closes the connection

you need to connect before running any queries, do this right after making an instance of the Database, and close it when your plugin disables in normal cases.

Creating a table:

db.executor().table("users").create() .ifNotExists() .column("id", "INTEGER") .column("name", "TEXT") .primaryKey("id") .unique("name") .execute();

Inserting Data:

db.executor().table("users") .insert() .value("id", 1) .value("name", "Steve") .execute();

This will insert (or replace) a row with id = 1 and name = "Steve".

Updating data:

db.executor().table("users") .update() .value("name", "Alex") .where("id = ?", 1) .execute();

Selecting data:

List<String> names = db.executor().table("users") .where("id > ?", 0) .select(rs -> rs.getString("name"));

Notes:

  • SQLite will automatically create the database file if it doesn't exist.

  • MySQL requires a reachable host and valid credentials.

  • All operations are safe to chain fluently. (as long as you know what you are doing)

  • Default values, foreign keys, uniqueness, and constraints are supported through the builder.

18 May 2025