Interface ModStorage
public interface ModStorage
The mod's tables in
zomboidforge.db, next to the world's save. Every table belongs to
the mod; this interface gives no access to the tables of other mods. It is not a security
boundary: mod code runs with the server's privileges and can open the file directly.
A record declares a table's columns: String, long/int,
double/float, boolean, byte[], UUID, Instant,
and enums. Primitive components cannot be null. Table and column names are snake_case
(lastPaid is stored as last_paid).
Calls block. On the main thread they are only allowed during startup (onLoad);
once the server runs they throw an IllegalStateException, so database I/O never costs
tick time. Use modThread() or async().
-
Method Summary
Modifier and TypeMethodDescription<R extends Record>
TableDefinition<R> A table with a schema version and migrations; seeTableDefinition.Opens the tablenamewith schema version 1 and no migrations.voidtransaction(Runnable work) Runsworkin one transaction: writes of this thread inside it are committed together, or not at all whenworkthrows.<T> Ttransaction(Supplier<T> work) Liketransaction(Runnable), returning the result ofwork.
-
Method Details
-
table
-
define
A table with a schema version and migrations; seeTableDefinition. -
transaction
Runsworkin one transaction: writes of this thread inside it are committed together, or not at all whenworkthrows.Storage of every mod waits while
workruns, soworkmust not wait for other threads, for example withmain().submit(...).join(). A backup waits at most 10 seconds for it and then runs without pausing storage. -
transaction
Liketransaction(Runnable), returning the result ofwork.
-