Title here
Summary here
New release had been published ✨
https://marco5dev.github.io/jsonverse-documentation/
Schema
like now you can use .Save
, .delete
, .update
, and .find
example bellowconst Jsonverse = require("jsonverse");
const db = new Jsonverse();
const { Schema } = Jsonverse;
const userSchema = new Schema({
name: {
type: String,
required: true,
},
age: {
type: Number,
required: true,
},
email: {
type: String,
required: true,
unique: true,
},
});
module.exports = db.model("User", userSchema);
const User = require("./path/to/UserSchema.js"); // Import the schema
const newUser = {
id: "123", // there is an auto id generator don't worry this is an example // or you can set a custom id by setting that id: what you want
name: "John Doe",
age: 30,
email: "johndoe@example.com",
}; // example data to save but we use json normally
// Save the new user
User()
.save(newUser)
.then(() => {
console.log("User saved successfully");
})
.catch((error) => {
console.error(error);
});
// Delete a user by query
const deleteQuery = { id: "123" };
User()
.delete(deleteQuery)
.then(() => {
console.log("User deleted successfully");
})
.catch((error) => {
console.error(error);
});
// Update a user by query
const updateQuery = { id: "123" }; // not only the id you use the name or any query like { name: ''John Doe }
const updates = { age: 31 }; // the data you want to update
User()
.update(updateQuery, updates)
.then(() => {
console.log("User updated successfully");
})
.catch((error) => {
console.error(error);
});
// Find users by query
const findQuery = { age: { $gte: 30 } };
// $gte: This operator stands for "greater than or equal to."
// It is used to filter documents where the specified field's value is greater than or equal to the specified value
User()
.find(findQuery)
.then((users) => {
console.log("Users found:", users);
})
.catch((error) => {
console.error(error);
});
Full Changelog: https://github.com/Marco5dev/jsonverse/compare/v1.2.7...v1.3.0