@akarui/aoi.db
Table Of Contents
About
Aoi.db is a collection of various database types to handle various types of data requirements!
Installation
npm i @akarui/aoi.db
yarn add @akarui/aoi.db
Types
- KeyValue - A simple database that stores key value pairs
- WideColumn - A database that stores data in a column
- Usage: good for getting separate columns related to a primary column
- Remote - A database that stores data in a remote server
- Usage: good for separating database extensive usage from main project/process
Setups
KeyValue
const { KeyValue } = require("@akarui/aoi.db")
import { KeyValue } from "@akarui/aoi.db"
const db = new KeyValue({
path: "./path/",
tables: ["table"],
});
db.on("ready", () => {
console.log("Database is ready!");
});
db.connect();
Reference: KeyValue
WideColumn
const { WideColumn, Column } = require("@akarui/aoi.db")
import { WideColumn, Column } from "@akarui/aoi.db"
const prime = new Column({
name: "id",
primary: true,
type: "bigint",
default:0n,
});
const xp = new Column({
name: "xp",
type: "number",
primary: false,
sortOrder: "DESC",
default : 0,
});
const db = new WideColumn({
path: "./path/",
encryptOption: {
securitykey: "a-32-characters-long-string-here",
},
tables: [
{
name: "main",
columns: [prime, xp ],
},
],
});
db.on("ready", () => {
console.log("Database is ready!");
});
db.connect();
Reference: WideColumn
Remote
Setting up the database server
const { Receiver } = require("@akarui/aoi.db");
import { Receiver } from "@akarui/aoi.db";
const rec = new Receiver({
logEncrypt: "a-32-characters-long-string-here",
logPath: "./logPath/",
wsOptions: {
port: portNo,
clientTracking: true,
},
whitelistedIps: "*",
});
rec.on("connect", () => {
console.log("connected");
});
rec.connect();
Reference: Receiver
Setting up the client
const { Transmitter, TransmitterFlags } = require("@akarui/aoi.db");
import { Transmitter, TransmitterFlags } from "@akarui/aoi.db";
const db = new Transmitter({
path: "websocket path",
databaseType: "KeyValue or WideColumn",
dbOptions: {
path: "./databasePath in remote server/",
encryptOption: {
securitykey: "a-32-characters-long-string-here",
enabled: true,
},
},
name: "username",
pass: "password",
flags: TransmitterFlags.READ_WRITE,
tables: ["table"],
});
db.on("ready", () => {
console.log("ready");
});
db.on("close", (code, reason) => {
console.log("[TRANSMITTER] => " + code + " " + reason);
});
db.connect();
Reference: Transmitter
Links