@aoitelegram/database
v1.1.1
Published
A custom database designed specifically for aoitelegram
Downloads
48
Maintainers
Readme
@aoitelegram/database
@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.
Installation
You can install the library via npm:
npm install @aoitelegram/database
Usage
AoiTelegram Connect
// 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();
FirebaseDB
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 }
MongoDB
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 }
MySqlDB
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 }
StorageDB
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 }
API Documentation
Please refer to the API Documentation for detailed information on classes, methods, and usage examples.
Contributing
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
.
License
This library is released under the MIT License.