@mxbe/database
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Database Management for Minecraft Bedrock Development

npm version

@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.

Features

  • 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

Installation

To install @mxbe/database in your minecraft add-on project, you have two options:

Option 1: Use the package manager

  1. Open a terminal and navigate to your project's root directory.
  2. Run the following command to install the package:
npx @mxbe/project init
  1. Choose dependencies addons in prompt @mxbe/database

Option 2: Install via npm

  1. Open a terminal and navigate to your project's root directory.
  2. Run the following command to install the package:
npm i @mxbe/database
  1. Use the module with ESBuild or Webpack

Option 3: Clone the repository

  1. Open a terminal and navigate to your project's root directory.
  2. Run the following command to clone the repository:
git clone https://github.com/sausage404/mxbe-database.git
  1. Copy the index.ts and index.d.ts or index.js file from the cloned repository into your project's scripts folder.

Basic Usage

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);
});

License

@mxbe/database is released under the GNU General Public License v3.

Issues

If you encounter any problems or have suggestions, please file an issue on the GitHub repository.

Readme

Keywords

none

Package Sidebar

Install

npm i @mxbe/database

Weekly Downloads

12

Version

0.0.1

License

GPL-3.0-only-3.0

Unpacked Size

50.2 kB

Total Files

8

Last publish

Collaborators

  • sausage404