[go: up one dir, main page]

xen.db
TypeScript icon, indicating that this package has built-in type declarations

4.0.3 • Public • Published

XenDB

Discord CI CodeFactor GitHub Release NPM

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.

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 } } <-
})();

Package Sidebar

Install

npm i xen.db

Homepage

xendb.js.org

Weekly Downloads

43

Version

4.0.3

License

MIT

Unpacked Size

57.9 kB

Total Files

38

Last publish

Collaborators

  • veilorth
  • reinhello