Examples

const { Dreamy } = require("dreamy-db");

// Project Folder > DataBase Folder > DB File
// Check above image
const db = new Dreamy({
  uri: `sqlite://DataBase/test.sqlite`,
});

db.on("error", (error) => console.error("Connection Error: ", error));

// This is example for Setting Database in different data Types
(async () => {
  await db
    .set("Profile", {
      id: 1234567890,
      Name: "Dreamy",
      verified: true,
      Friends: ["vshal", "sai"],
      height: 6.2,
      Balance: 450,
      Job: null,
    })
    .then(console.log("Created User Profile in Database")) // Logs Once Database Created || else gets error.
    .catch(console.error);

  // Returns an array that contains the keys of each element.
  await db
    .keys()
    .then((data) => console.log(data))
    .catch(console.error);

  // Returns an array that contains the values of each element.
  await db
    .values()
    .then((data) => console.log(data))
    .catch(console.error);

  // Gets all the elements from the database.
  await db
    .all()
    .then((data) => console.log(data))
    .catch(console.error);

  // Clears all elements from the database.
  await db
    .clear()
    .then(console.log("Removed all elements from DB"))
    .catch(console.error);

  // Deletes an element from the database by key.
  await db.delete("profile").then(console.log).catch(console.error); // Returns true
  
})(); // Callback

Last updated