> For the complete documentation index, see [llms.txt](https://db.coolstone.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://db.coolstone.dev/4/core/update.md).

# Update

## Append to Record <a href="#append" id="append"></a>

{% tabs %}
{% tab title="Append" %}
{% code lineNumbers="true" %}

```javascript
await db.get('tag').append(content)
```

{% endcode %}
{% endtab %}

{% tab title="Prepend" %}
{% code lineNumbers="true" %}

```javascript
await db.get('tag').prepend(content)
```

{% endcode %}
{% endtab %}
{% endtabs %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>content</td><td>The content to add</td><td>Any</td><td>true</td></tr></tbody></table>

## Truncate Record <a href="#length" id="length"></a>

{% code lineNumbers="true" %}

```javascript
await db.get('tag').truncate(length)
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>length</td><td>New file length</td><td>Number</td><td>true</td></tr></tbody></table>

## Edit Record Content <a href="#overwrite" id="overwrite"></a>

{% hint style="danger" %}
This will overwrite your record with the content provided.
{% endhint %}

{% tabs %}
{% tab title="1" %}
{% code lineNumbers="true" %}

```javascript
await db.get('tag').write(content)
```

{% endcode %}
{% endtab %}

{% tab title="2" %}
{% code lineNumbers="true" %}

```javascript
await db.write("tag", content)
```

{% endcode %}
{% endtab %}
{% endtabs %}

<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>The Record's tag</td><td>String</td><td>true</td></tr><tr><td>content</td><td>The content to overwrite with</td><td>Any (must match file extension)</td><td>true</td></tr></tbody></table>

## Safe & Atomic Writing

{% hint style="info" %}
These functions are already used internally, but you can also use them yourself
{% endhint %}

{% tabs %}
{% tab title="Safe Write" %}
{% code lineNumbers="true" %}

```javascript
await db.safeWrite('tag', content)
```

{% endcode %}

| Parameter    | About           | Type   |
| ------------ | --------------- | ------ |
| tag          | The record tag  | String |
| Content      | The new content | Any    |
| {% endtab %} |                 |        |

{% tab title="Atomic Update" %}
{% code lineNumbers="true" %}

```javascript
await db.atomicUpdate('tag', updater)
```

{% endcode %}

| Name          | About                                 | Type     |
| ------------- | ------------------------------------- | -------- |
| tag           | The record tag                        | String   |
| updater       | A function to call to mutate the data | Function |
| {% endtab %}  |                                       |          |
| {% endtabs %} |                                       |          |

## Modify a Key

{% hint style="danger" %}

### JSON Only

This function only modifies objects.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
await db.get('tag').kv(key, value)
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Typr</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>key</td><td>The key to set the value to</td><td>String</td><td>true</td></tr><tr><td>value</td><td>The value to set the key to. If <code>value</code> is omitted, it will return the value of <code>key</code></td><td>Any</td><td>true</td></tr></tbody></table>

## Modify a Record's Tag <a href="#tag" id="tag"></a>

{% tabs %}
{% tab title="1" %}
{% code lineNumbers="true" %}

```javascript
await db.get('old_tag').setTag('new_tag')
```

{% endcode %}
{% endtab %}

{% tab title="2" %}
{% code lineNumbers="true" %}

```javascript
await db.setTag('old_tag', 'new_tag')
```

{% endcode %}
{% endtab %}
{% endtabs %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>old_tag</td><td>The current tag of the Record.</td><td>String</td><td>true</td></tr><tr><td>new_tag</td><td>The new tag you want for the Record.</td><td>String</td><td>true</td></tr></tbody></table>

## Empty Record

Emptying a Record deletes the Record content but preserves the file.

{% code lineNumbers="true" %}

```javascript
await db.get('tag').empty()
```

{% endcode %}

### Check if a Record is empty

{% code lineNumbers="true" %}

```javascript
await db.get('tag').isEmpty()
```

{% endcode %}
