Gathering detailed insights and metrics for create-verse.db
Gathering detailed insights and metrics for create-verse.db
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.
npm install create-verse.db
Typescript
Module System
Node Version
NPM Version
69.7
Supply Chain
95.6
Quality
90.7
Maintenance
100
Vulnerability
98.9
License
TypeScript (99.98%)
JavaScript (0.02%)
Total Downloads
3,973
Last Day
4
Last Week
71
Last Month
223
Last Year
3,973
8 Stars
161 Commits
2 Watching
4 Branches
5 Contributors
Latest Version
0.4.9
Package Id
create-verse.db@0.4.9
Unpacked Size
87.24 kB
Size
22.06 kB
File Count
56
NPM Version
11.0.0
Node Version
22.12.0
Publised On
23 Dec 2024
Cumulative downloads
Total Downloads
Last day
-91.8%
4
Compared to previous day
Last week
-5.3%
71
Compared to previous week
Last month
-18%
223
Compared to previous month
Last year
0%
3,973
Compared to previous year
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:
1npm install verse.db 2yarn add verse.db
to get started setup the database connection uding .connect method
1const versedb = require("verse.db"); 2// or 3import versedb from "verse.db"; 4 5const adapterOptions = { 6 adapter: "json" | "yaml" | "sql", // the type of the adapter json, yaml or sql 7 dataPath: "./Data", // the path of the data folder 8 devLogs: { enable: true, path: "./Logs" }, // the path to the logs folder 9 encryption: { secret: "" }, // Add your secrete key for securing your data "Note: if you forgot your Key. It will be hard to get your data" 10 backup: { enable: false, path: "", retention: 0 }, // Under Development: Backing up 11}; 12 13const db = new versedb.connect(adapterOptions); // use the connect method to connect a database
Note*: that you can make a multiple databases in the same time with/without the same extention
1const dataname = "users"; // the name of the datafile without the extention 2const result = await db.load(dataname); 3 4console.log(result);
1// Arrange 2const data = [ 3 { _id: "1234", name: "John" }, 4 { _id: "5678", name: "Jane" }, 5]; 6const dataname = "users"; 7 8// Act 9const result = await db.add(dataname, data);
result:
1{ 2 "acknowledged": true, 3 "message": "Data added successfully.", 4 "results": [ 5 { "_id": "1234", "name": "John" }, 6 { "_id": "5678", "name": "Jane" } 7 ] 8}
1// Arrange 2const data = [ 3 { _id: "1234", name: "John" }, 4 { _id: "5678", name: "Jane" }, 5]; 6const query = { name: "John" }; 7const dataname = "users"; 8 9// Act 10const result = await db.find(dataname, query); 11 12// Assert 13expect(result).toEqual({ 14 acknowledged: true, 15 message: "Found data matching your query.", 16 results: { _id: "1234", name: "John" }, 17});
1// Arrange 2const data = [ 3 { _id: "1234", name: "John" }, 4 { _id: "5678", name: "Jane" }, 5]; 6const query = { _id: "1234" }; 7const dataname = "users"; 8 9// Act 10const result = await db.remove(dataname, query, { docCount: 2 }); // (OPTIONAL) docCount => number of documents matchs the query 11 12// Assert 13expect(result).toEqual({ 14 acknowledged: true, 15 message: "1 document(s) removed successfully.", 16 results: null, 17});
Update the data you want with the query you want using .update method:
1// Arrange 2const dataname = "users"; 3const data = [ 4 { _id: "1234", name: "John", age: 30, hobbies: ["Reading"], friends: ["Jane"], email: "john@example.com" }, 5 { _id: "5678", name: "Jane", age: 25, hobbies: ["Gardening"], friends: ["John"], email: "jane@example.com" }, 6]; 7const updateQuery = { 8 $set: { name: "Mike" }, // Set the name field to "Mike" 9 $inc: { age: 1 }, // Increment the age field by 1 10 $addToSet: { hobbies: "Swimming" }, // Add "Swimming" to the hobbies array if not already present 11 $push: { friends: "Alice" }, // Push "Alice" into the friends array 12 $unset: { email: "" }, // Remove the email field 13 $currentDate: { lastModified: true } // Set the lastModified field to the current date 14}; 15const upsert = true; 16 17// Act 18const result = await db.update(dataname, { _id: "1234" }, updateQuery, upsert); 19 20// Assert 21expect(result).toEqual({ 22 acknowledged: true, 23 message: "1 document(s) updated successfully.", 24 results: { 25 _id: "1234", 26 name: "Mike", 27 age: 31, 28 hobbies: ["Reading", "Swimming"], 29 friends: ["Jane", "Alice"], 30 lastModified: expect.any(Date) 31 }, 32});
1// Arrange 2const dataname = "users"; 3const query = { age: { $gte: 25 } }; // Find documents with age greater than or equal to 25 4const updateQuery = { 5 $set: { name: "Updated Name" }, // Set the name field to "Updated Name" 6 $inc: { age: 1 }, // Increment the age field by 1 7 $addToSet: { hobbies: "Swimming" }, // Add "Swimming" to the hobbies array if not already present 8 $push: { friends: "Alice" }, // Push "Alice" into the friends array 9 $unset: { email: "" }, // Remove the email field 10 $currentDate: { lastModified: true } // Set the lastModified field to the current date 11}; 12 13// Act 14const result = await db.updateMany(dataname, query, updateQuery); 15 16// Results: 17 return { 18 acknowledged: true, 19 message: `${updatedCount} document(s) updated successfully.`, 20 results: updatedDocument, 21 };
1// Arrange 2const dataname = "users"; 3const dropResult = await db.drop(dataname); 4 5// Results: 6 return { 7 acknowledged: true, 8 message: `All data dropped successfully.`, 9 results: '', 10 };
1 2// Arrange 3const collectionFilters = [ 4 { 5 dataname: "users", 6 displayment: 5, 7 filter: { age: 30, gender: "male" }, // Search for male users with age 30 8 }, 9 { 10 dataname: "products", 11 displayment: null, // No limit on displayment 12 filter: { category: "electronics", price: { $lt: 500 } }, // Search for electronics products with price less than 500 13 }, 14]; 15 16// Perform the search 17const searchResult = await db.search("/path/to/data folder", collectionFilters); 18 19// Assert 20expect(searchResult.acknowledged).toBe(true); 21expect(searchResult.message).toBe("Successfully searched in data for the given query."); 22expect(searchResult.results).toEqual({ 23 users: [ 24 // Assert the first 5 male users with age 30 25 expect.objectContaining({ age: 30, gender: "male" }), 26 expect.objectContaining({ age: 30, gender: "male" }), 27 expect.objectContaining({ age: 30, gender: "male" }), 28 expect.objectContaining({ age: 30, gender: "male" }), 29 expect.objectContaining({ age: 30, gender: "male" }), 30 ], 31 products: [ 32 // Assert the products that match the filter criteria 33 expect.objectContaining({ category: "electronics", price: expect.toBeLessThan(500) }), 34 // Add more assertions for other products if needed 35 ], 36});
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
Repository github.com/marco5dev/verse.db
Homepage versedb.jedi-studio.com
Weekly Downloads 158
Version 1.1.4
License MIT
Unpacked Size 448 kB
Total Files 70
Issues 0
Pull Requests 0
Last publish 2 hours ago
Collaborators zenith-79 marco5dev Try on RunKit Report malware
No vulnerabilities found.
No security vulnerabilities found.