An Open-Source Asynchronous NodeJS Database Driver
npm install xen.dbbash
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)
$3
`js
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 } } <-
`
$3
`js
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 } } <-
})();
``