Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

v1.3.0

Compare
Choose a tag to compare
@Marco5dev Marco5dev released this 17 Sep 11:41
· 50 commits to master since this release

What Changed ?

  • #24 Improving the functions with promises
  • #23 Add Database Schema
  • Create new documentation Link https://marco5dev.github.io/jsonverse-documentation/
  • Update some functions name to use with the Schema like now you can use .Save, .delete, .update, and .find example bellow
const 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);
// Create a new user

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: v1.2.7...v1.3.0