# Examples

<div align="left"><img src="https://2831894753-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MbLzG7u_bt3-zigj5-h%2F-MbfZVIrepKOPsPQJAgv%2F-Mbfa00Tiyk138i2Xcn9%2FScreenshot%20from%202021-06-08%2017-57-35.png?alt=media&#x26;token=6f62597a-5946-482a-8d79-19848c47c49f" alt=""></div>

```javascript
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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dreamyplayer.gitbook.io/dreamy-db/api/examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
