Package group.worldstandard.pudel.api.database
package group.worldstandard.pudel.api.database
Plugin data persistence and database management API.
This package provides a JPA-like repository pattern for plugin data persistence. Each plugin gets its own isolated database schema, ensuring data separation between plugins. Raw SQL is not allowed - all interactions go through the repository pattern.
Key Components:
PluginDatabaseManager- Main database access interfacePluginRepository- Repository for CRUD operationsPluginKeyValueStore- Simple key-value storageTableSchema- Table schema definition builderEntity- Annotation for entity classesColumn- Annotation for field-to-column mappingColumnType- Enum of supported column typesPluginMigration- Interface for schema migrationsQueryBuilder- Fluent query builder
Basic Usage:
@Entity
public class UserSetting {
private Long id;
private Long userId;
private String key;
private String value;
// getters and setters...
}
// In your plugin:
PluginDatabaseManager db = context.getDatabaseManager();
// Create table
TableSchema schema = TableSchema.builder("user_settings")
.column("user_id", ColumnType.BIGINT, false)
.column("key", ColumnType.STRING, 100, false)
.column("value", ColumnType.TEXT, true)
.build();
db.createTable(schema);
// Get repository
PluginRepository<UserSetting> repo = db.getRepository("user_settings", UserSetting.class);
// CRUD operations
UserSetting setting = new UserSetting();
setting.setUserId(12345L);
setting.setKey("theme");
setting.setValue("dark");
repo.save(setting);
Optional<UserSetting> found = repo.findById(setting.getId());
Key-Value Store:
PluginKeyValueStore kv = db.getKeyValueStore();
kv.set("config.enabled", true);
boolean enabled = kv.getBoolean("config.enabled", false);
- Since:
- 2.3.0
-
ClassDescriptionAnnotation for customizing field-to-column mapping.Supported column types for plugin database tables.Annotation for mapping entity classes to database tables.Database manager for plugin data persistence.Database statistics.Simple key-value store for plugin configuration and small data.Interface for plugin database migrations.Functional interface for data migrations.Helper interface for migration operations.Repository interface for CRUD operations on plugin database tables.QueryBuilder<T>Query builder for complex database queries.Schema definition for a plugin database table.Builder class for constructing
TableSchemainstances.Represents the definition of a database column within a table schema.Represents the definition of an index in a database table schema.