# Quick Start

### Create a Remote Server

If you want, you can create a server and access that server remotely. If you are not going to use a server, you can also use it locally.

```javascript
const example_server = new <PeakDB>.Server({
  "port": 4951,
  "users": [
    {
      "username": "fir4tozden",
      "password": "ZdJuTNqUXpqNrw2H",
      "permissions": 1 << 0 | 1 << 3 // read and delete
    },
    {
      "username": "nehir",
      "password": "yPIkXo3l82aMbJZc",
      "permissions": 1 << 0 | 1 << 1 | 1 << 2 // read, write and update
    }
  ]
});
```

### Connect to Remote Server

After creating the server, connect to the server.

```javascript
const example_connection = new <PeakDB>.Connection({
  "address": "127.0.0.1:4951",
  "authorization": {
    "username": "fir4tozden",
    "password": "ZdJuTNqUXpqNrw2H"
  },
  "auto_reconnect": true,
  "auto_reconnect_interval": 5
});
```

### Create a Collection

You need to create a collection to store your data. You can do this with the following constructor. If you want to store your data as a collection, you need to set the collection type to `0`. In this case, the data can be filtered more easily. If you want to make it key-value, you need to set the collection type as `1`. In this case, you can assign a value to a key. For example `username=fir4tozden`.

```javascript
const example_collection = new <PeakDB | Connection>.Collection({
  "name": "EXAMPLE_COLLECTION",
  "type": 0,
  
  /*
    For document-based collections
  */
  "id_length": 32,
  "indicate_created_at": false,
  "indicate_created_timestamp": true,
  "indicate_updated_at": false,
  "indicate_updated_timestamp": true,
  "indicate_archived_at": false,
  "indicate_archived_timestamp": true,
  "indicate_unarchived_at": false,
  "indicate_unarchived_timestamp": true,
  
  /*
    Can be used on all collection types
  */
  "save_timeout": 1,
  "save_directly_after": 5,
  "cache_retention_time": 10,
  "backup_retention_time": 3,
  "caching": true,
  "auto_create_backup": true,
  "detailed_debugger_logs": true,
  "activate_destroy_function": false
});
```

### Store Data

Each collection type has different methods to store your data. For example, you can use this method in document-based collections. For key-value-based collections you can use it like this for example.

```javascript
accounts.insert({"email": "fir4tozden@gmail.com", "username": "fir4tozden", "password": "12345678", "region": "Muğla"});
/*
  {
    "_id": "RMmXZVDfQrVLQwFlquMPb98XNUCxQ6MM",
    "_updated": false,
    "_archived": false,
    "_created_at": 2022-03-20T00:00:00.000Z,
    "_created_timestamp": 1647745200000,
    "email": "fir4tozden@gmail.com",
    "username": "fir4tozden",
    "password": "12345678",
    "region": "Muğla"
  }
*/
```

For key-value-based collections you can use it like this for example.

```javascript
user_settings.set("USER_1", {"friend_requests": true});
/*
  {
    "friend_requests": true
  }
*/
```

These are just a few examples of being able to use PeakDB. Check out the documentation for more.


---

# 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://peakdb.gitbook.io/docs/quick-start.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.
