verse.db isn't just a database, it's your universal data bridge. Designed for unmatched flexibility, security, and performance, verse.db empowers you to manage your data with ease.
The verse.db package is a powerful utility designed to simplify the management of data files within a designated folder. It offers methods for adding, editing, deleting, and retrieving data from JSON, YAML, SQL & more files. This wiki provides detailed examples and usage scenarios to help you effectively implement the verse.db package in your projects.
To begin using the verse.db package, you'll need to install it via npm. Open your terminal and run the following command:
Note*: that you can make a multiple databases in the same time with/without the same extention
const dataname = "users";
const result = await db.load(dataname);
console.log(result);
const data = [
{ _id: "1234", name: "John" },
{ _id: "5678", name: "Jane" },
];
const dataname = "users";
const result = await db.add(dataname, data);
result:
{
"acknowledged": true,
"message": "Data added successfully.",
"results": [
{ "_id": "1234", "name": "John" },
{ "_id": "5678", "name": "Jane" }
]
}
const data = [
{ _id: "1234", name: "John" },
{ _id: "5678", name: "Jane" },
];
const query = { name: "John" };
const dataname = "users";
const result = await db.find(dataname, query);
expect(result).toEqual({
acknowledged: true,
message: "Found data matching your query.",
results: { _id: "1234", name: "John" },
});
const data = [
{ _id: "1234", name: "John" },
{ _id: "5678", name: "Jane" },
];
const query = { _id: "1234" };
const dataname = "users";
const result = await db.remove(dataname, query, { docCount: 2 });
expect(result).toEqual({
acknowledged: true,
message: "1 document(s) removed successfully.",
results: null,
});
Update the data you want with the query you want using .update method:
const dataname = "users";
const data = [
{ _id: "1234", name: "John", age: 30, hobbies: ["Reading"], friends: ["Jane"], email: "john@example.com" },
{ _id: "5678", name: "Jane", age: 25, hobbies: ["Gardening"], friends: ["John"], email: "jane@example.com" },
];
const updateQuery = {
$set: { name: "Mike" },
$inc: { age: 1 },
$addToSet: { hobbies: "Swimming" },
$push: { friends: "Alice" },
$unset: { email: "" },
$currentDate: { lastModified: true }
};
const upsert = true;
const result = await db.update(dataname, { _id: "1234" }, updateQuery, upsert);
expect(result).toEqual({
acknowledged: true,
message: "1 document(s) updated successfully.",
results: {
_id: "1234",
name: "Mike",
age: 31,
hobbies: ["Reading", "Swimming"],
friends: ["Jane", "Alice"],
lastModified: expect.any(Date)
},
});
const dataname = "users";
const query = { age: { $gte: 25 } };
const updateQuery = {
$set: { name: "Updated Name" },
$inc: { age: 1 },
$addToSet: { hobbies: "Swimming" },
$push: { friends: "Alice" },
$unset: { email: "" },
$currentDate: { lastModified: true }
};
const result = await db.updateMany(dataname, query, updateQuery);
return {
acknowledged: true,
message: `${updatedCount} document(s) updated successfully.`,
results: updatedDocument,
};
const dataname = "users";
const dropResult = await db.drop(dataname);
return {
acknowledged: true,
message: `All data dropped successfully.`,
results: '',
};
- To Search Multiples Of Data
const collectionFilters = [
{
dataname: "users",
displayment: 5,
filter: { age: 30, gender: "male" },
},
{
dataname: "products",
displayment: null,
filter: { category: "electronics", price: { $lt: 500 } },
},
];
const searchResult = await db.search("/path/to/data folder", collectionFilters);
expect(searchResult.acknowledged).toBe(true);
expect(searchResult.message).toBe("Successfully searched in data for the given query.");
expect(searchResult.results).toEqual({
users: [
expect.objectContaining({ age: 30, gender: "male" }),
expect.objectContaining({ age: 30, gender: "male" }),
expect.objectContaining({ age: 30, gender: "male" }),
expect.objectContaining({ age: 30, gender: "male" }),
expect.objectContaining({ age: 30, gender: "male" }),
],
products: [
expect.objectContaining({ category: "electronics", price: expect.toBeLessThan(500) }),
],
});
The verse.db package simplifies the management of JSON data files within a specified folder. With the provided examples and usage instructions, you'll be able to efficiently integrate the verse.db package into your projects to streamline data operations.
Package Sidebar
Install
npm i verse.db