Skip to content
machinastudiosPublic

About

Simple database API with abstraction layer for Hytale plugins and mods.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

18 Commits

Folders and files

Repository files navigation

MDatabase

SQL database abstraction for Hytale plugins and mods (SQLite, MySQL, PostgreSQL).

Overview

MDatabase provides a JPA/Hibernate layer so Hytale plugins can use multiple SQL backends with programmatic configuration (no persistence.xml required). It includes an ORM-style Model<T> helper and a migration framework.

Responsibilities:

  • SQLDatabaseProvider base class for dialect-specific setup
  • Runtime JDBC driver download and management
  • Model<T> static query helpers with provider injection
  • Database-agnostic migrations executed on initialization

Run

Build with Maven

cd mdatabase
mvn clean install

Build with marn

cd mdatabase
marn build
marn link

Important: Install to the local Maven repository (~/.m2/repository) before other projects depend on it.

Dependency

<dependency>
    <groupId>com.machina</groupId>
    <artifactId>mdatabase</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>

Usage

SQLite provider

public class SQLDatabaseProvider extends com.machina.mdatabase.providers.database.SQLDatabaseProvider {
    public SQLDatabaseProvider() {
        super(DatabaseDialect.SQLITE, "path/to/database.db");
        registerModel(MyModel.class);
        registerMigration(new MyMigration());
    }
}

MySQL / PostgreSQL provider

public class SQLDatabaseProvider extends com.machina.mdatabase.providers.database.SQLDatabaseProvider {
    public SQLDatabaseProvider() {
        super(DatabaseDialect.MYSQL, "mydatabase");
        setConnectionConfig("localhost", 3306, "root", "password", "mydatabase");
        registerModel(MyModel.class);
        registerMigration(new MyMigration());
    }
}

Call setConnectionConfig() before initialize() for network SQL backends. Default ports: MySQL 3306, PostgreSQL 5432.

Model example

@Entity
public class MyModel extends Model<MyModel> {
    @Id
    public UUID uuid;
    public String name;

    public MyModel() {
        super(MyModel.class);
    }

    public static MyModel findByName(String name) {
        return Model.findOne(MyModel.class, Map.of("name", name));
    }
}

Migration example

Implement Migration with getId(), getDescription(), shouldRun(EntityManager), and execute(EntityManager). Use DatabaseMigrationUtils for portable column/table checks.

Project conventions

Area Rule
Providers root/providers/database/, extend SQLDatabaseProvider
Models root/database/models/, class names end with Model
MongoDB Future separate provider (not in mdatabase)

Supported today: SQLite, MySQL, PostgreSQL.

See AGENTS.md for workspace coding standards.

About

Simple database API with abstraction layer for Hytale plugins and mods.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages