# Versioning

## 1. Temporarily-Stored Versions <a href="#temp" id="temp"></a>

{% hint style="info" %}
Dubnium may create a directory named `versions` in `.dubnium`, but will not create files there unless [new file versioning](#2.-new-file) is enabled.
{% endhint %}

Save versions to `db.versions.temp`. Temporary versions are removed when the process starts. This can be enabled when initializing Dubnium.

{% code overflow="wrap" lineNumbers="true" %}

```javascript
const db = new Dubnium('dir', 'txt', { versioning:{ temp:true } })
```

{% endcode %}

### Structure

```javascript
{ tag: [ { date: "2023-04-14T17:27:24.930Z", content: 'content 1' } ] }
```

## 2. File Versions

Create a new file in `.dubnium/versions/{tag_here}`. This can be enabled when initializing Dubnium.

{% code lineNumbers="true" %}

```javascript
const db = new Dubnium('dir', 'txt', { versioning:{ file:true } })
```

{% endcode %}

### Structure

The files are stored in `.dubnium/versions/TAG/DATE` and the file contents are identical to the Record.

## Limit Versions

When initializing, add `max:number` to the versioning object to limit the number of stored versions.

{% code lineNumbers="true" %}

```javascript
const db = new Dubnium('dir', 'txt', { versioning:{ file:true, max:10 } })
```

{% endcode %}

### Retroactively limit versions

{% code lineNumbers="true" %}

```javascript
db.versions.setLength(max)
```

{% endcode %}

<table><thead><tr><th>Paramter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>max</td><td>The new limit</td><td>Number</td><td>true</td></tr></tbody></table>

## Read A Version

{% hint style="warning" %}
This is only for file versions. To read a temporary version, access it from `db.versions.temp`
{% endhint %}

{% tabs %}
{% tab title="From Date" %}
If you know the ISO date for the version you would like to read (programmatically), you can use `readFromDate`

{% code lineNumbers="true" %}

```javascript
db.versions.readFromDate('tag', 'date')
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>tag</td><td>Record tag</td><td>String</td><td>true</td></tr><tr><td>date</td><td>Date of version</td><td>String (ISO date)</td><td>true</td></tr></tbody></table>
{% endtab %}

{% tab title="From Index" %}
Alternatively, if you know the index for the version you would like to read (programmatically), you can use `readFromIndex`

{% code lineNumbers="true" %}

```javascript
db.versions.readFromIndex('tag', index)
```

{% endcode %}

<table><thead><tr><th>Paramter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>tag</td><td>Record tag</td><td>String</td><td>true</td></tr><tr><td>index</td><td>Index of version</td><td>Number</td><td>true</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

## Stop Recording Versions

You can stop versioning anytime; the parameters are the same as the initialization.

{% code lineNumbers="true" %}

```javascript
db.stopVersioning({ temp:true, file:true })
```

{% endcode %}

## Resume Recording

{% code lineNumbers="true" %}

```javascript
db.startVersioning({ temp:true, file:true })
```

{% endcode %}


---

# 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://db.coolstone.dev/3/api/versioning.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.
