SQL database abstraction for Hytale plugins and mods (SQLite, MySQL, PostgreSQL).
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:
SQLDatabaseProviderbase 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
cd mdatabase
mvn clean installcd mdatabase
marn build
marn linkImportant: Install to the local Maven repository (~/.m2/repository) before other projects depend on it.
<dependency>
<groupId>com.machina</groupId>
<artifactId>mdatabase</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>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());
}
}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.
@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));
}
}Implement Migration with getId(), getDescription(), shouldRun(EntityManager), and execute(EntityManager). Use DatabaseMigrationUtils for portable column/table checks.
| 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.