@mxbe/database
is a lightweight and flexible database solution for Minecraft Bedrock Edition (MCBE) add-ons. It provides a simple API for creating, reading, updating, and deleting data within your MCBE scripts.
- Dynamic property-based storage system
- Type-safe operations with TypeScript generics
- Case-insensitive search capabilities
- Complex filtering conditions (==, !=, >, <, >=, <=, contains, startsWith, endsWith)
- Customizable collection names
- Automatic ID generation
- Memory-efficient storage using JSON serialization
To install @mxbe/database
in your minecraft add-on project, you have two options:
- Open a terminal and navigate to your project's root directory.
- Run the following command to install the package:
npx @mxbe/project init
- Choose dependencies addons in prompt
@mxbe/database
- Open a terminal and navigate to your project's root directory.
- Run the following command to install the package:
npm i @mxbe/database
- Open a terminal and navigate to your project's root directory.
- Run the following command to clone the repository:
git clone https://github.com/sausage404/mxbe-database.git
- Copy the
index.ts
andindex.d.ts
orindex.js
file from the cloned repository into your project's scripts folder.
Let's walk through how to use the database in your minecraft bedrock. We'll cover the essential operations with practical examples.
Create a Database Instance With TypeScript
import * as mc from "@minecraft/server";
import Database, { CollectionValidator } from "@mxbe/database";
// Define the structure of your data
interface User {
id: string;
name: string;
age: number;
money: number;
}
const validateUser: CollectionValidator<User> = {
id: (value) => value.length > 0,
name: (value) => value.length > 0,
age: (value) => value > 0,
money: (value) => value >= 0
}
// Initialize the database
const database = new Database<User>("users", mc.world, validateUser);
// Create a new user
const newUser: User = {
id: "user123",
name: "John Doe",
age: 30,
money: 1000,
};
// Insert the new user into the database
database.create(newUser);
// Read all users from the database
const users = database.findMany().forEach((user) => {
console.log(user);
});
@mxbe/database is released under the GNU General Public License v3.
If you encounter any problems or have suggestions, please file an issue on the GitHub repository.