A Minecraft Bedrock asynchronous database with unlimited storage. This database works on Dynamic Properties. The database is designed for optimal performance and has a built in queue system for async calls.
First you will need to make a table, you can do this by either adding a key to the TABLES
object in tables.ts or
creating a variable assigned to a Database
instance. A Cool thing about this database is that it supports full type safety and
you can predefine the types of the keys and values of the database.
import { Database } from "./Database.ts";
const table = new Database<any>("test");
Setting data is very simple and will send back a promise that can be awaited to let you know when the data is successfully saved in the entities.
table.set("someRandomKey", "someRandomValue");
async function saveSomeData() {
await table.set("someRandomKey", "someRandomValue");
console.warn("Data has been set");
}
This database supports Asynchronous calls that can be used for grabbing data at any time (which includes on world load), or you simply can grab data from memory.
table.getSync("someRandomKey").then((v) => {
console.warn(v); // "someRandomValue"
});
Or you can simply call from memory using:
Warning: This can throw errors if data is tried to grab before world load.
const value = table.get("someRandomKey");
Returns a iterable list of keys that are stored in this table.
Warning: This can throw errors if data is tried to grab before world load.
table.keys(): any[]
table.keysSync(): Promise<any[]>
Returns a iterable list of all values that are stored in this table.
Warning: This can throw errors if data is tried to grab before world load.
table.values(): any[]
table.valuesSync(): Promise<any[]>
Checks if a key exists on this table and returns boolean.
Warning: This can throw errors if data is tried to grab before world load.
table.has(key: any): boolean
table.hasSync(key: any): Promise<boolean>
Returns a Object of all keys and values on this table.
Warning: This can throw errors if data is tried to grab before world load.
table.collection(): { [any]: any }
table.collection(): Promise<{ [any]: any }>
Deletes a key on this table and returns a boolean if it successfully deleted the key.
table.delete(key: any): Promise<boolean>
Clears the entire table and sets it back to a empty object, then returns once finished.
table.clear(): Promise<void>