@aoitelegram/database
is a Node.js library for managing various types of databases, including Firebase Realtime Database, MongoDB, and a generic file-based storage solution. It provides a unified interface for performing CRUD operations, managing events, and checking database responsiveness.
You can install the library via npm:
npm install @aoitelegram/database
// CommonJS
const { AoiClient } = require("aoitelegram");
const { AoiDB } = require("@aoitelegram/database");
// Esm/TypeScript
import { AoiClient } from "aoitelegram";
import { AoiDB } from "@aoitelegram/database";
const database = new AoiDB({
type: "storage",
logger: true,
options: {
tables: ["main"],
},
});
const bot = AoiClient("token", {
extension: [database],
// ...other
});
database.timeoutCommand({
id: "other",
code: "$print[Yesssss!;$timeoutData[key]]",
});
bot.addCommand({
command: "start_timeout",
code: "$setTimeout[other;10m;{ key: 'Hello World' }]",
});
// Set user variables in a table.
database.variables(
{
sempai: 10,
string: "Hello, world!",
aoijs: true,
webapp: false,
mz: [],
},
"main",
);
bot.connect();
import { FirebaseDB } from "@aoitelegram/database";
// Create a FirebaseDB instance
const db = new FirebaseDB("<your-firebase-database-url>", {
projectId: "<your-firebase-priject-id>",
tables: ["users", "posts"], // Optional: specify tables
});
// Connect to the Firebase database
await db.connect();
// Perform operations such as get, set, delete, etc.
await db.set("users", "user1", { name: "John", age: 30 });
const user = await db.get("users", "user1");
console.log(user); // Output: { name: 'John', age: 30 }
import { MongoDB } from "@aoitelegram/database";
// Create a MongoDB instance
const db = new MongoDB("<your-mongodb-url>", {
tables: ["users", "posts"], // Specify tables
});
// Connect to the MongoDB database
await db.connect();
// Perform operations such as get, set, delete, etc.
await db.set("users", "user1", { name: "John", age: 30 });
const user = await db.get("users", "user1");
console.log(user); // Output: { name: 'John', age: 30 }
import { MySqlDB } from "@aoitelegram/database";
// Create a MongoDB instance
const db = new MySqlDB(<url> and <connection options> (host, user, password, port),
["users", "posts"], // Specify tables
);
// Connect to the MongoDB database
await db.connect();
// Perform operations such as get, set, delete, etc.
await db.set("users", "user1", { name: "John", age: 30 });
const user = await db.get("users", "user1");
console.log(user); // Output: { name: 'John', age: 30 }
import { StorageDB } from "@aoitelegram/database";
// Create a StorageDB instance
const db = new StorageDB({
path: "./data", // Optional: specify data directory
tables: ["users", "posts"], // Optional: specify tables
});
// Connect to the storage database
await db.connect();
// Perform operations such as get, set, delete, etc.
await db.set("users", "user1", { name: "John", age: 30 });
const user = await db.get("users", "user1");
console.log(user); // Output: { name: 'John', age: 30 }
Please refer to the API Documentation for detailed information on classes, methods, and usage examples.
Contributions are welcome! If you find any issues or have suggestions for improvements, please create a GitHub
issue or submit a pull request. Additionally, feel free to reach out to me on Telegram via my group AoiTelegram or on Discord using my username sempaika_chess
.
This library is released under the MIT License.