XenDB
XenDB is an open-source asynchronous NodeJS database driver. This library was built for a simple usage to access, store, and update data at any time easily. These data are stored persistently and securely via various of database supported.
- Discord: discord.gg/78RyqJK
- GitHub: github.com/helloreindev/xen.db
- NPM: npmjs.com/package/xen.db
Installation
# For SQLite
npm install xen.db better-sqlite3
# For MySQL
npm install xen.db promise-mysql
Please follow the provided troubleshooting guide if you are having issues installing it.
Example
These are the examples used with different database driver. More database driver will be supported in future versions (such as MongoDB)
SQLite
const { SQLiteDriver } = require("xen.db");
// For custom file path, use the 'fileName' option.
// Eg. new SQLiteDriver({ fileName: "path/mydb.sqlite" });
const db = new SQLiteDriver();
db.set("Name", "Hellorein");
// -> { Name: "Hellorein" } <-
db.set("World", { Time: "Day", Money: 15000 });
// -> { World: { Time: "Day", Money: 15000 } } <-
db.get("World");
// -> { World: { Time: "Day", Money: 15000 } } <-
db.push("Cart", ["Weapon A", "Weapon B"]);
// -> { Cart: ["Weapon A", "Weapon B"] } <-
db.add("World.Money", 5000);
// -> { World: { Time: "Day", Money: 20000 } } <-
MySQL
const { MySQLDriver } = require("xen.db");
const db = new MySQLDriver({
database: "test",
host: "localhost",
password: "password",
user: "root",
});
(async () => {
// Connect the database to MySQL. This always come first.
await db.connect();
await db.set("Name", "Hellorein");
// -> { Name: "Hellorein" } <-
await db.set("World", { Time: "Day", Money: 15000 });
// -> { World: { Time: "Day", Money: 15000 } } <-
await db.get("World");
// -> { World: { Time: "Day", Money: 15000 } } <-
await db.push("Cart", ["Weapon A", "Weapon B"]);
// -> { Cart: ["Weapon A", "Weapon B"] } <-
await db.add("World.Money", 5000);
// -> { World: { Time: "Day", Money: 20000 } } <-
})();