Create your fastest Database
What are DataBuilder?
The DataBuilder
class is a lightweight and efficient tool designed to facilitate quick database interactions directly using JSON files. It allows developers to perform basic operations such as creating tables, inserting items, querying data, and deleting records without the overhead of more complex database systems. This approach is particularly useful for small projects, prototyping, and situations where simplicity and speed are paramount.
Key Features of DataBuilder
- Simple JSON-based storage: Data is stored in a straightforward JSON file, making it easy to view and edit directly.
- CRUD operations: Supports Create, Read, Update, and Delete operations directly through its methods.
- No external dependencies: Uses Node.js's native fs module to handle file operations, avoiding the need for external database drivers or ORMs.
How to use it?
Start by instancied DataBuilder
js
import { DataBuilder } from 'umbrae';
const data = new DataBuilder();
Here's an example to manage users experience in you guild
js
import { EventBuilder, Events, DataBuilder } from "umbrae";
const data = new DataBuilder();
export default EventBuilder(
{
name: Events.MessageCreate,
description: 'When a message is sent.'
},
async (message) => {
if (!data.get('users')) {
data.create('users');
}
let user = await data.query('users', { id: message.author.id })?.[0]
if (!user) {
user = await data.insert('users', {
id: message.author.id,
xp: 0,
max: 100,
})
}
const randomXp = (min = 15, max = 25) => {
return Math.floor(Math.random() * (max - min + 1) + min);
}
user.xp += randomXp();
data.update();
}
)
All the DataBuilder
methods
create
js
import { DataBuilder } from "umbrae";
const data = new DataBuilder();
data.create('tableName') // create a table with the name specified.
get
js
import { DataBuilder } from "umbrae";
const data = new DataBuilder();
data.get('tableName') //get a table with the name specified if she exist.
insert
js
import { DataBuilder } from "umbrae";
const data = new DataBuilder();
data.insert('tableName', { key: value, key: value }) // insert an object in a table if she exist.
query
js
import { DataBuilder } from "umbrae";
const data = new DataBuilder();
data.query('tableName', { key: value, key: value }) // get an array of object with the keys and value matched.
delete
js
import { DataBuilder } from "umbrae";
const data = new DataBuilder();
data.delete('tableName') // delete a table.
// or
data.delete('tableName', { key: value, key: value }) // delete an object.
update
beta
js
import { DataBuilder } from "umbrae";
const data = new DataBuilder();
data.update(data); // save the database.
Tips
When using the DataBuilder
, the data will be automatically saved except for modifications after-call.