# Home

### Welcome!

Want to learn more about Dubnium? You're in the right place! Read these pages to learn more about the package!

### What is Dubium?

Dubnium is a package available on [NPM](https://npmjs.com/package/dubnium). Dubnium allows you to create local databases perfect for storing a few values for an app's configuration or thousands of users' data on a server. However you need to store your data, Dubnium can help you out.

{% embed url="<https://npmjs.com/dubnium>" %}

### How does it work?

Dubnium is based on the `fs` module. It creates and stores any file in your chosen directory and can be retrieved, renamed, moved, cloned, and more!

### Why use Dubnium?

Check out the key features page!

{% content-ref url="/pages/1AnJQMTTpWtF1bXPsxvo" %}
[Key Features](/key-features)
{% endcontent-ref %}

### Ready to get started?

#### Latest version

{% content-ref url="/spaces/vcFdfD9ESUdjAVaOUmlR" %}
[v3](https://db.coolstone.dev/3/)
{% endcontent-ref %}

#### Browser version

{% content-ref url="/spaces/vFt6Or1YIUF7W4j4iUZ7" %}
[Browser](https://db.coolstone.dev/browser/)
{% endcontent-ref %}

Docs for older versions are available [here](/get-started)

### Need help and can't find it on the docs?

[Ask for help](https://github.com/coolstone-tech/dubnium/discussions/new?category=help) on Github!

{% embed url="<https://github.com/coolstone-tech/dubnium/discussions>" %}

### Found a bug or issue while using Dubnium?

Open up an issue on GitHub

{% embed url="<https://github.com/coolstone-tech/dubnium/issues>" %}

### Want to know what's coming soon?

Check out the Dubnium Roadmap

{% embed url="<https://github.com/orgs/coolstone-tech/projects/1>" %}

### Want to support development?

{% embed url="<https://patreon.com/coolstone>" %}


# Key Features

Learn why you should use Dubnium!

### Local & Unlimited

Since Dubnium is locally stored, the only limit to the amount of data stored is what **you** want! You also don't have to worry about any outages on our end or need any internet connection to use Dubnium¹!

## Customizable

Is Dubnium missing something you need? Extend it!

<pre class="language-javascript" data-line-numbers><code class="lang-javascript"><strong>const Dubnium = require("dubnium")
</strong>class Dubnium2 extends Dubnium {

constructor(dirPath, ext){
super(dirPath,ext)
}

printPath(tag) => {
console.log(this.find(tag))
}
}

new Dubnium2('dir','json').printPath('tag')
</code></pre>

### Small

Dubnium is approximately 35 **kB**, while [Mongoose](https://www.npmjs.com/package/mongoose) is over 2 **MB**.

### Supports any file type

You can use any file type supported by Node.js!

### Multiple databases in *one* project

Dubnium allows you to have as many databases as you need!

### Keep track of versions

Dubnium can also record versions of Records automatically. [Learn more](/3/api/versioning)

### Tons of other features

Overwrite, tag/content searching, renamable Records, CLI, powerful deletion methods, [browser](https://db.coolstone.dev/browser/) support, middleware, and more!

### Private

**Nobody** but the people that have access to the directory you created can **ever** see a Record and data never leaves the device it was created on.

### ECMAScript (ESM) & Commonjs supported

Dubnium [v2](https://db.coolstone.dev/2/) and [v1](https://db.coolstone.dev/1/) support Commonjs & ECMAScript modules! Dubnium v0 is ECMAScript only, however, the [Dubnium Archive](https://github.com/coolstone-tech/dubnium-archive) has a Commonjs version.

### Free & Open-sourced

Dubnium is free to use for personal & commercial use. It is also open-sourced and licensed under the MIT license.

### Browser Support

Want to use a similar API on your browser²? You can! Dubnium for browser uses `localStorage` (or `sessionStorage`) to store data. Check out[ the docs](https://db.coolstone.dev/browser/) to get started!

### Updates

Dubnium is actively being developed and new features are added often. If you have an idea, please tell us!

1: After installing

2: Some methods may not be available due to browser limitations.


# Get Started

## Ready to get started?

### Latest version

{% content-ref url="/spaces/feSpBBIwpWeqLZM360eK" %}
[v4](https://db.coolstone.dev/4/)
{% endcontent-ref %}

### Want to use Dubnium in your browser?

{% content-ref url="/spaces/vFt6Or1YIUF7W4j4iUZ7" %}
[Browser](https://db.coolstone.dev/browser/)
{% endcontent-ref %}

### Older Versions

We recommend using the latest version.&#x20;

{% content-ref url="/spaces/vcFdfD9ESUdjAVaOUmlR" %}
[v3](https://db.coolstone.dev/3/)
{% endcontent-ref %}

{% content-ref url="/spaces/u7oRoN9oGoMk6xetuV0e" %}
[v2](https://db.coolstone.dev/2/)
{% endcontent-ref %}

{% content-ref url="/spaces/R9vVFsB2Mknm5FEZfKHO" %}
[v1](https://db.coolstone.dev/1/)
{% endcontent-ref %}

{% content-ref url="/spaces/mhaxBlUDyAQyxTUUqn5I" %}
[v0](https://db.coolstone.dev/0/)
{% endcontent-ref %}


# Overview

We recommend you read the full docs, but this will get you started with the basics.

## Install&#x20;

Dubnium is available on npm or GitHub (requires Node.js) and is available for CommonJS and ECMAScript modules.

### npm <a href="#npm" id="npm"></a>

{% hint style="info" %}
We strongly recommend using npm.
{% endhint %}

```bash
npm i dubnium
```

Check out our [npm page](https://npmjs.com/dubnium).

### GitHub <a href="#github" id="github"></a>

<https://github.com/coolstone-tech/dubnium>

## Initialize

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

```javascript
const Dubnium = require('dubnium') 
const db = new Dubnium('dirPath','ext')
```

{% endcode %}
{% endtab %}

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

```javascript
import Dubnium from 'dubnium'
const db = new Dubnium('dirPath','ext')
```

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

## Make Your First Record

{% code lineNumbers="true" %}

```javascript
db.create('tag', content)
```

{% endcode %}

## Get a Record

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

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

{% endcode %}
{% endtab %}

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

```javascript
db.getAll({ tagOnly:false })
```

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

## Delete a Record

{% code lineNumbers="true" %}

```javascript
db.get('tag').delete()
```

{% endcode %}

## Modify a Record

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

{% code lineNumbers="true" %}

```javascript
db.get('tag').write("new_content")
```

{% endcode %}
{% endtab %}

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

```javascript
db.get("old_tag").setTag("new_tag")
```

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

#### Check out our full docs for more API methods and in-depth explanations.


# Initialize

How to get started with Dubnium.

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

```javascript
const Dubnium = require('dubnium')
const db = new Dubnium('dirPath', options)
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
const db = new (require("dubnium"))("dir", options)
```

{% endcode %}
{% endtab %}

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

```javascript
import Dubnium from 'dubnium'
const db = new Dubnium('dirPath','ext', options)
```

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

{% hint style="info" %}
You can initialize as many databases as you want
{% endhint %}

### Parameters

<table><thead><tr><th width="197">Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>dir</td><td>The path to the directory to store Records.</td><td>String</td><td>true</td></tr><tr><td>options.ext</td><td>Custom file extension (default: <code>json</code>) </td><td>String</td><td>false</td></tr><tr><td>options</td><td>Options</td><td>Object</td><td>false</td></tr><tr><td>options.name</td><td>Database name</td><td>String</td><td>false</td></tr><tr><td>options.force</td><td>Enable force overwriting of a preexisting Record.</td><td>Boolean</td><td>false</td></tr><tr><td>options.versioning</td><td>Read more in <a href="/pages/3HHPjwUPXgwBXF68CseI">Versioning</a>.</td><td>Object</td><td>false</td></tr><tr><td>options.requireRoot</td><td>Functions to require root access to run</td><td>Array</td><td>false</td></tr><tr><td>options.trash</td><td>Dir to trash Records in </td><td>String</td><td>false</td></tr><tr><td>options.metadata</td><td>Set to false to disable metadata tracking</td><td>Bool</td><td>false</td></tr></tbody></table>


# Create

## In Database

<pre class="language-javascript" data-line-numbers><code class="lang-javascript"><strong>db.create('tag', content, ttl)
</strong></code></pre>

<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 new Record's tag</td><td>String</td><td>true</td></tr><tr><td>content</td><td>The Record's content</td><td>Any</td><td>true</td></tr><tr><td>ttl</td><td>Record's time to live</td><td>Number</td><td>false</td></tr></tbody></table>

### TTL <a href="#ttl" id="ttl"></a>

When you create a Record, you can set a TTL for that Record.

### Retroactively Set

{% code lineNumbers="true" %}

```javascript
db.get('tag').expire(ttlMs)
```

{% endcode %}

#### Monitor TTL

By default, Dubnium will only check TTL when you read a Record. However, you can call `monitorTTL()` to auto check TTL. However, this will read metadata for **all** Records.

{% code lineNumbers="true" %}

```javascript
db.monitorTTL(interval)
```

{% endcode %}

| Parameter | About                         | Type   |
| --------- | ----------------------------- | ------ |
| interval  | Interval of time for checking | Number |

#### Stop Monitoring

{% code lineNumbers="true" %}

```javascript
db.stopTTLMonitor()
```

{% endcode %}

## Record Class

{% code lineNumbers="true" %}

```javascript
onst Record = require("dubnium/record")
new Record( path, dbInstance )
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>path</td><td>File path</td><td>String</td><td>true</td></tr><tr><td>dbInstance</td><td>Dubnium instance</td><td>Dubnium</td><td>true</td></tr></tbody></table>

## Clone <a href="#ttl" id="ttl"></a>

{% code lineNumbers="true" %}

```javascript
db.get('tag').clone('target')
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>target</td><td>Target directory to clone the record in.</td><td>String</td><td>true</td></tr></tbody></table>


# Get

How to get Record content and information.

## Get Record From Tag <a href="#from-tag" id="from-tag"></a>

{% code lineNumbers="true" %}

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

{% 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>The Record's tag</td><td>String</td><td>true</td></tr></tbody></table>

## Read <a href="#content" id="content"></a>

{% tabs %}
{% tab title="DB level" %}

```javascript
await db.read('tag')
```

{% endtab %}

{% tab title="Record level" %}
{% code lineNumbers="true" %}

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

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

## Get Path <a href="#path" id="path"></a>

{% tabs %}
{% tab title="Locate method" %}
{% code lineNumbers="true" %}

```javascript
db.locate('tag')
```

{% 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's tag</td><td>string</td><td>true</td></tr></tbody></table>
{% endtab %}

{% tab title="Path property" %}
{% code lineNumbers="true" %}

```javascript
db.get('tag').path
```

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

## Get Tag <a href="#tag" id="tag"></a>

{% code lineNumbers="true" %}

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

{% endcode %}

## Exists <a href="#exists" id="exists"></a>

{% hint style="info" %}
This will only return `true` or `false`.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
await db.has('tag')
```

{% 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>The tag to check for</td><td>String</td><td>true</td></tr></tbody></table>

## Get All Records

{% code lineNumbers="true" %}

```javascript
await db.getAll({tagOnly:false, limit:10, filter})
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>options.tagOnly</td><td>Set to true to return an array of tags instead of Records</td><td>Boolean</td><td>false</td></tr><tr><td>options.limit</td><td>Max results</td><td>Number</td><td>false</td></tr><tr><td>options.filter</td><td>Filter results</td><td>Function</td><td>false</td></tr></tbody></table>

## Find Record

Similar to `getAll`, but returns the first match.

{% code lineNumbers="true" %}

```javascript
await db.find(tag => {})
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>filter</td><td>Filter results</td><td>Function</td><td>false</td></tr></tbody></table>


# Update

How to edit Record content and attributes.

## 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 %}


# Delete

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

```javascript
db.get('tag').delete()
```

{% endcode %}
{% endtab %}

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

```javascript
db.delete('tag')
```

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

## Trash

If you set `trash`, Records will **not** be deleted, but rather moved to your trash.

#### Delete All from Trash

{% code lineNumbers="true" %}

```javascript
db.emptyTrash()
```

{% endcode %}

#### Delete from Trash

{% code lineNumbers="true" %}

```javascript
db.deleteFromTrash('tag')
```

{% endcode %}

| Parameter | About                     | Type   |
| --------- | ------------------------- | ------ |
| tag       | Tag of the trashed record | String |

#### Restore From Trash

<pre class="language-javascript" data-line-numbers><code class="lang-javascript"><strong>db.restoreFromTrash('tag')
</strong></code></pre>

| Parameter | About                     | Type   |
| --------- | ------------------------- | ------ |
| tag       | Tag of the trashed record | String |

## Close

Delete **all** records & the directory

{% code lineNumbers="true" %}

```javascript
db.close()
```

{% endcode %}

## Wipe

Delete **all** records & *preserve* the directory

{% code lineNumbers="true" %}

```javascript
db.wipe()
```

{% endcode %}

## Delete Old Records

{% code lineNumbers="true" %}

```javascript
db.deleteOld({ ms:5, seconds:5, minutes:5, hours:5, days:0})
```

{% endcode %}

Requires at least one of the options below (multiple options will stack)

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-hidden data-type="checkbox">Required</th></tr></thead><tbody><tr><td>ms</td><td>Milliseconds</td><td>Number</td><td>false</td></tr><tr><td>seconds</td><td>Seconds</td><td>Number</td><td>false</td></tr><tr><td>minutes</td><td>Minutes</td><td>Number</td><td>false</td></tr><tr><td>hour</td><td>Hours</td><td>Number</td><td>false</td></tr><tr><td>days</td><td>Days</td><td>Number</td><td>false</td></tr></tbody></table>

## Delete Large Records

{% code lineNumbers="true" %}

```javascript
db.deleteLarge(size)
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-hidden data-type="checkbox">Required</th></tr></thead><tbody><tr><td>size</td><td>Size of the file in bytes</td><td>Number</td><td>false</td></tr></tbody></table>

## Safe Unlink

{% hint style="info" %}
This function is already used internally, but you can also use it yourself
{% endhint %}

{% code lineNumbers="true" %}

```javascript
db.safeUnlink(tag)
```

{% endcode %}


# Batch

{% code lineNumbers="true" %}

```javascript
// --- basic usage ---
await db.batch([
    { type: 'write',  tag: 'user:1', data: { name: 'Alice', role: 'admin', score: 100 } },
    { type: 'kv',     tag: 'user:2', key: 'score', value: 50 },
    { type: 'delete', tag: 'user:3' },
])

// --- best-effort mode: failures don't abort the batch ---
const results = await db.batch([
    { type: 'write', tag: 'user:1', data: { name: 'Alice', role: 'admin', score: 200 } },
    { type: 'write', tag: 'user:99', data: { name: 'Ghost' } },
    { type: 'kv',   tag: 'user:2', key: 'score', value: 75 },
], { mode: 'allSettled' })

const failed = results.filter(r => r.status === 'rejected')
if (failed.length) {
    failed.forEach(r => console.error(`Op[${r.index}] failed: ${r.reason.message}`))
}

// --- concurrency cap: useful for large batches hitting the lockfile system ---
const bulkUpdates = Array.from({ length: 200 }, (_, i) => ({
    type: 'kv',
    tag:  `user:${i + 1}`,
    key:  'updatedAt',
    value: new Date().toISOString(),
}))

await db.batch(bulkUpdates, { concurrency: 10 })
```

{% endcode %}


# Metadata

## Base

{% code lineNumbers="true" %}

```javascript
db.metadata('tag')
```

{% endcode %}

| Parameter | About                     | Type   |
| --------- | ------------------------- | ------ |
| tag       | Tag of the trashed record | String |

## Read

{% code lineNumbers="true" %}

```javascript
await db.metadata('tag').read()
```

{% endcode %}

## Write

{% code lineNumbers="true" %}

```javascript
await db.metadata('tag').write(data)
```

{% endcode %}

| Parameter | About                                                            | Type   |
| --------- | ---------------------------------------------------------------- | ------ |
| data      | <p>{<br>createdAt: Date,<br>updatedAt: Date,<br>ttl: 0,<br>}</p> | Object |

## Delete

{% code lineNumbers="true" %}

```javascript
await db.metadata('tag').delete()
```

{% endcode %}


# Middleware

Dubnium has built-in Express middleware functions to manage Records. Data is never sent to the client without your permission.

## Setup

{% code lineNumbers="true" %}

```javascript
const dbMiddleware = require('dubnium/middleware')
const dubnium = require('dubnium')
const db = new dubnium(...)
const middleware = dbMiddleware(db)
```

{% endcode %}

## Parameters

{% hint style="info" %}
If `tag.key` or `content.key` is omitted, the `from` value is used.
{% endhint %}

<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>First param to set tag info.</td><td>Object</td><td>true</td></tr><tr><td>tag.from</td><td>Part of the <code>req</code> object to get the tag from (e.g. <code>headers</code> or <code>body</code>)</td><td>String</td><td>true</td></tr><tr><td>tag.key</td><td>Key from the <code>from</code> object to get tag from.</td><td>String</td><td>false</td></tr><tr><td>content</td><td>Second param to set content info</td><td>Object</td><td>true</td></tr><tr><td>content.from</td><td>Part of the <code>req</code> object to get the content from (e.g. <code>headers</code> or <code>body</code>)</td><td>String</td><td>true</td></tr><tr><td>content.key</td><td>Key from the <code>from</code> object to get tag from.</td><td>String</td><td>false</td></tr></tbody></table>

## Methods

### Create

{% code lineNumbers="true" %}

```javascript
app.get('/new', middleware.create({ from:"query", key:"tag" }, { from:"query", key:"content" }), (req, res) => {
// Creates a record with the tag and content from the query
})
```

{% endcode %}

### Get

{% code lineNumbers="true" %}

```javascript
app.get('/:tag', middleware.get({ from:"params", key:"tag" }), (req, res) => {
// Access the record directly from req.record, if it exists
})
```

{% endcode %}

### DB

{% code lineNumbers="true" %}

```javascript
app.get('/db', middleware.db(), (req, res) => {
// Access the database directly from req.db
})
```

{% endcode %}

### Delete

{% code lineNumbers="true" %}

```javascript
app.get('/', middleware.delete({ from:"headers", key:"id" }), (req, res) => {
    res.send('Account deleted.')
})
```

{% endcode %}

### Edit

{% code lineNumbers="true" %}

```javascript
app.get('/', middleware.edit({ from:"body" }, { from:"content" }), (req, res) => {
    res.send('Account edited!')
})
```

{% endcode %}

### Other

{% code lineNumbers="true" %}

```javascript
app.get('/', middleware.other('function', ...args), (req, res) => {
    res.send(`Ran ${req.db.function} with args ${req.db.args}`)
    // req.db['function'] is the requested function
    // req.db.function is the name of the requested function
    // req.db.args is the requested args
    // req.db.result is the result of the function
})
```

{% endcode %}


# Versioning

## Structure

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

## Limit Versions

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

{% code lineNumbers="true" %}

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

{% endcode %}

## Read A Version

{% code lineNumbers="true" %}

```javascript
db.get('tag').getVersion('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>

## Manually Save Snapshot

{% hint style="info" %}
This allows you to create a version at any point in time, even if automatic versioning is disabled or the limit has been reached.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
db.get('tag').saveSnapshot()
```

{% endcode %}

### Example

{% code lineNumbers="true" %}

```javascript
await db.create('snapshot_test', { value: 'snapshot' });
const { timestamp, record:snapshotRecord } = await db.get('snapshot_test').saveSnapshot();
const snapshotData = await db.get('snapshot_test').getVersion(timestamp);
assert.equal(snapshotData, (await snapshotRecord.read(true)), 'Snapshot data mismatch');
```

{% endcode %}

## Generator

{% code lineNumbers="true" %}

```javascript
for (const version of db.get('tag').versions()) {
const { timestamp, record } = version
}
```

{% endcode %}

## Rollback

{% code lineNumbers="true" %}

```javascript
db.get('tag').rollback('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>false</td></tr></tbody></table>


# Synchronization

## Overwrite from another Record <a href="#syncwith" id="syncwith"></a>

{% code lineNumbers="true" %}

```javascript
await db.get('tag').syncWith('_tag')
```

{% 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>The tag of the Record you want to get the content from.</td><td>String</td><td>true</td></tr></tbody></table>

## Watch a File

Watch the record for changes and emit events when the record is modified. The watcher will continue to run until you call the `stop` function returned by this method.

{% code lineNumbers="true" %}

```javascript
const { watcher, stop } = db.get('tag').watch()

for await (const event of watcher) {
       console.log(`Event type: ${event.eventType}`);
        console.log(`Filename: ${event.filename}`);
}

stop() // Stop watching
```

{% endcode %}

## Duplicate Entire Database

Copy all records from the current database to a new target directory, creating a new Dubnium instance for the target directory and writing each record's data to the corresponding file in the target directory.

{% code lineNumbers="true" %}

```javascript
db.copyTo('path')
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>path</td><td>Path to new dir</td><td>String</td><td>true</td></tr></tbody></table>

## Replication / Continuous Sync

Set up real-time replication of records to a new target directory by listening for record creation, updates, and deletions in the current database and applying those changes to the target directory. This method creates a new Dubnium instance for the target directory and registers event listeners for 'create', 'edit', and 'delete' events emitted by the current database. When a record is created, edited, or deleted in the current database, the corresponding event listener will be triggered, and it will perform the same operation on the target database to keep it in sync. The method returns a function that can be called to stop the replication by removing the event listeners.

{% code lineNumbers="true" %}

```javascript
db.replicateTo('path')
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>path</td><td>Path to new dir</td><td>String</td><td>true</td></tr></tbody></table>

### Stop Replication

<pre class="language-javascript" data-line-numbers><code class="lang-javascript"><strong>const { close } = db.replicateTo('path');
</strong>
close();
</code></pre>

### Flush Replication Queue

<pre class="language-javascript" data-line-numbers><code class="lang-javascript"><strong>const { flush } = db.replicateTo('path');
</strong>
await db.create('rep', { after: true });

await new Promise(r => flush().then(r));

await replica.has('rep');
</code></pre>

### Replication Status

<pre class="language-javascript" data-line-numbers><code class="lang-javascript"><strong>const { status, replica } = db.replicateTo('path');
</strong>
status.closed // true/false
status.pending // Number of tasks in queue
status.replicaDir // Dir of replica

replica // Dubnium instance at replica
</code></pre>


# Indexing

## In Memory

{% hint style="info" %}
This takes precedence over in storage indexes.&#x20;
{% endhint %}

{% code lineNumbers="true" %}

```javascript
await db.buildIndex(limit)
```

{% endcode %}

## In Storage

{% code lineNumbers="true" %}

```javascript
await db.buildPersistentIndex()
```

{% endcode %}


# Miscellaneous

Other functions provided by Dubnium.

## Directory

### Change <a href="#change-dir" id="change-dir"></a>

{% code lineNumbers="true" %}

```javascript
db.config.dir = './new/dir'
```

{% endcode %}

### Make <a href="#make-dir" id="make-dir"></a>

{% code lineNumbers="true" %}

```javascript
await db.dir()
```

{% endcode %}

## Read Configuration <a href="#get-dir" id="get-dir"></a>

{% code lineNumbers="true" %}

```
db.config[setting]
```

{% endcode %}

## Search Content

Convert content to String and return the result of [`String.search()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)

{% code lineNumbers="true" %}

```javascript
await db.get("tag").search('query')
```

{% endcode %}

## Create Symlink to a Record <a href="#create-symlink" id="create-symlink"></a>

{% code lineNumbers="true" %}

```javascript
await db.get('tag').symlink('./path/to/symlink') 
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>target</td><td>Path to a directory where the symlink will be created</td><td>String</td><td>true</td></tr></tbody></table>

## Get Record's Stats <a href="#get-stats" id="get-stats"></a>

{% code lineNumbers="true" %}

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

{% endcode %}

## End

If you want to *end* a string of methods, you can with `.end()`. **Note: this is not required.**

{% code lineNumbers="true" %}

```javascript
db.get("tag").write(content).end()
```

{% endcode %}

## Exit <a href="#exit" id="exit"></a>

If you wish to exit the Record editor API, call the `exit()` method and it will return the class.

{% code lineNumbers="true" %}

```javascript
db.get('tag').write(content).exit().//any_class_function
```

{% endcode %}

## Internal Functions

Dubnium exports some internal functions that can be used in your project.

{% code lineNumbers="true" %}

```javascript
require('dubnium/functions')
```

{% endcode %}

## Aliases

Don't like the name we chose for a method? Set an alias!&#x20;

{% code lineNumbers="true" %}

```javascript
db.alias('alais_here', 'existing_function')
```

{% endcode %}

For example,

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

```javascript
db.alias('val', 'getFromValue') // Allows you to call db.val() instead of db.getFromValue()
```

{% endcode %}

## Iterate

{% code lineNumbers="true" %}

```javascript
for(record of db) {
console.log(record)
}
```

{% endcode %}

## Lock/Unlock

Uses [proper-lockfile](https://www.npmjs.com/package/proper-lockfile).

{% code lineNumbers="true" %}

```javascript
db.get('tag').lock() // Locks the file
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
db.get('tag').umlock() // Unlocks the file
```

{% endcode %}

## Get Database Name <a href="#all" id="all"></a>

{% hint style="info" %}
Names are derived from the directory's base name or can manually be set in config object when initializing.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
db.name
```

{% endcode %}


# Events

Dubnium uses the built-in Events module to send messages when something happens!

| Event       | Callback Arguments     | About                                                                               |
| ----------- | ---------------------- | ----------------------------------------------------------------------------------- |
| create      | Tag & content          | Fires when a Record is created.                                                     |
| delete      | Tag                    | Fires when a Record is deleted.                                                     |
| edit        | Tag, old & new content | Fires when a Record's value changes.                                                |
| retagged    | Old & new tag          | Fires when a Record's tag changes.                                                  |
| wipe        | Directory path         | Fires when the database is wiped.                                                   |
| close       | Directory path         | Fires when the database is closed.                                                  |
| deleteOld   | Options                | Fires when `deleteOld` is called. (Will also fire `delete` for any Records deleted) |
| dir         | Directroy path         | Fires when the directory is created.                                                |
| clone       | Tag, target            | Fires when a Record is cloned.                                                      |
| symlink     | Tag & path to symlink  | Fires when a Symlink is created.                                                    |
| deleteLarge | size                   | Fires when [`deleteLarge()`](/4/core/delete#delete-large-records) is called.        |

### Example

{% code lineNumbers="true" %}

```javascript
db.on('create', (tag, content) => { 
console.log(`${tag} was created!`) 
})
```

{% endcode %}


# CLI

Run Dubnium functions from your command-line!

## Install

### Install in your project

```bash
npm i dubnium@latest
```

### Install globally

```bash
sudo npm i dubnium@latest -g
```

## Use

If you installed it [globally](#install-globally)

```bash
dubnium <command>
```

If you installed it [in your project](#install-in-your-project)

```bash
npx dubnium <command>
```

### Commands

Commands are **similar** to the API. If you want to call a function on a Record, do **not** put `get().func()`. Instead, make the command just `func` and put the Record's tag as the first arg when prompted.

### Example

![](/files/GPi9ilO2XHRwf6BMak1k)

The CLI will ask for a few values, and then the method will be run and the return value is logged to the console.

## Invoke Programmatically

{% hint style="warning" %}
Make sure the command is present when you run the file.

```bash
node index.js <command>
```

{% endhint %}

{% code lineNumbers="true" %}

```javascript
require("dubnium/cli")
```

{% endcode %}


# JSON

## Make a new Template <a href="#new" id="new"></a>

{% hint style="info" %}
Set any value to `required` to require that value to be set.
{% endhint %}

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

```javascript
const Template = require('dubnium/template')
const template = new Template({
id:"required",
name:"",
password:"required"
})
```

{% endcode %}
{% endtab %}

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

```javascript
import Template from 'dubnium/template'
const template = new Dubnium.Template({
id:"",
name:"",
password:""
})
```

{% 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>template</td><td>The object to base the new Template on.</td><td>Object</td><td>true</td></tr></tbody></table>

## Use Template <a href="#use" id="use"></a>

{% code lineNumbers="true" %}

```javascript
database.create('tag', template.use('123456',"John","password"))
```

{% endcode %}

The parameters of this function are what will be set to the value of the keys in order.

**Example**: the parameter`John` will be the value of `name`since they are both in the second position.

## Full code example <a href="#example" id="example"></a>

{% code title="json\_template.js" lineNumbers="true" %}

```javascript
const { Dubnium, Template } = require('dubnium')
// import { Dubnium, Template } from 'dubnium' // for ESM
const database = new Dubnium('./db','json') // Initialize a database

const template = new Template({ // Make a new Template
id:"",
name:"",
password:""
})

database.create('tag', template.use('123456',"John","password")) // Create a Record based on the Template
```

{% endcode %}


# String

## Make a new Template <a href="#new" id="new"></a>

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

```javascript
const { Dubnium, Template } = require('dubnium') // require('dubnium') is an alias of require('dubnium').Dubnium
const template = new Template("Hello, {0}")
```

{% endcode %}
{% endtab %}

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

```javascript
import { Dubnium, Template } from 'dubnium'
const template = new Template("Hello, {0}", TemplateTypes.STRING)
```

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

## Use Template <a href="#use" id="use"></a>

{% code lineNumbers="true" %}

```javascript
database.create('tag', template.use("World"))
```

{% endcode %}

The parameters of this function determine the index's value in the string.

**Example**: the parameter `0` will be the value of `World` since they are both at index 0.

## Full Example <a href="#example" id="example"></a>

{% code title="string\_template.js" lineNumbers="true" %}

```javascript
const { Dubnium, Template } = require('dubnium')
// import { Dubnium, Template } from 'dubnium' // for ESM
const database = new Dubnium('./db', 'txt') // Initialize a database

const template = new Template("Hello, {0}") // Make a new Template

database.create('tag', template.use('World')) // Create a Record based on the Template
```

{% endcode %}


# Collections

Handle schema-based validation and data creation in a database.

### Setup

{% code lineNumbers="true" %}

```js
const Collection = require('dubnium/collection');
const collection = new Collection(db, name, schema)
```

{% endcode %}

| Parameter | Type             | About                                                                                                                                                                                                                               |
| --------- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `db`      | Object           | The database instance this collection is associated with.                                                                                                                                                                           |
| `name`    | String           | The prefix or name of the collection.                                                                                                                                                                                               |
| `schema`  | Object \| String | Schema definition for validating data. Can be: - A string: any non-null value is valid. - An object: keys are field names and values are either expected types (`"string"`, `"number"`, etc.) or `"required"` for mandatory fields. |

## Validate a Record

* If schema is a string, validation passes if `data` is not `undefined` or `null`.
* If schema is an object:
  * Each key in the schema must exist in the data.
  * `"required"` fields must be non-empty.
  * Each field must match the expected type.

{% code lineNumbers="true" %}

```javascript
collection.validate(data)
```

{% endcode %}

**Parameters**

| Name   | Type   | About                 |
| ------ | ------ | --------------------- |
| `data` | Object | The data to validate. |

**Returns**

| Type    | About                                                     |
| ------- | --------------------------------------------------------- |
| Boolean | `true` if the data matches the schema, `false` otherwise. |

Creates a new record in the database after validating it against the schema.

{% code lineNumbers="true" %}

```javascript
collection.create('tag', data)
```

{% endcode %}

**Parameters**

| Name   | Type            | About                             |
| ------ | --------------- | --------------------------------- |
| `tag`  | String          | Unique identifier for the record. |
| `data` | Object \|String | Data to be stored.                |

**Returns**

* A promise resolving to the result of `db.create(tag, data)`

## Full Example

{% code lineNumbers="true" %}

```js
const Collection = require('./Collection');
const db = require('./myDatabase'); // Must implement create(tag, data)

const userSchema = {
  username: 'string',
  email: 'string',
  password: 'required'
};

const users = new Collection(db, 'users', userSchema);

async function addUser() {
  const userData = { username: 'alice', email: 'alice@example.com', password: 'secret' };
  try {
    const result = await users.create('user_1', userData);
    console.log('User created:', result);
  } catch (err) {
    console.error(err);
  }
}

addUser();
```

{% endcode %}


# Setup

### 1. Find an extension.

For this guide, we will use a custom function. You can find one on your own, or use our [Extension Finder](https://coolstone.dev/dubnium/extensions/).

{% code title="createHelloWorld.js" lineNumbers="true" %}

```javascript
(db) => {
if(!db) throw new Error("This extension requires database permissions")
db.create('hello', `Hello, World!`)
}
```

{% endcode %}

### 2. Define permissons

{% code lineNumbers="true" %}

```javascript
const { extensionPermissions } = require('dubnium')
const permissions = new extensionPermissions(true, false, [ 'edit' ]) 
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>record</td><td>Allow access to the Record when extending the record editor API</td><td>true</td></tr><tr><td>database</td><td>Allow access to the entire database when extending the database.</td><td>true</td></tr><tr><td>filterList</td><td>An array of function names to omit from an extension.</td><td>false</td></tr></tbody></table>

### 3. Add to Dubnium

{% code lineNumbers="true" %}

```javascript
db.extend('name', require('./extension'), permissions)
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
db.get('tag').extend('name', require('./extension'), permissions)
```

{% endcode %}

### 4. Use the extension

{% code lineNumbers="true" %}

```javascript
db.name()
```

{% endcode %}

### Full Example

{% code title="createHelloWorld.js" lineNumbers="true" %}

```javascript
db.extend('createHelloWorld', (db) => {
if(!db) throw new Error("This extension requires database permissions")
db.create('hello', `Hello, World!`)
}, new extensionPermissions(false, true))

db.createHelloWorld()
```

{% endcode %}


# Create

## Create

If you want to create a Plugin to publish on NPM, copy the code below and put the source in the exported method.

{% hint style="info" %}
Write your plugins in Commonjs to allow either Commonjs or ESM support!
{% endhint %}

{% code title="new\_extension.js" overflow="wrap" lineNumbers="true" %}

```javascript
module.exports = (database, record) => {
// database & record can be null, depending on the permissions. Be sure to be able to handle that!
}
```

{% endcode %}

## Publish

If you want to add it to our Extension Finder, publish it to npm with `dubnium` as a keyword.


# Update Log

Date format is MM/DD/YYYY

## Get the Latest Version <a href="#get" id="get"></a>

```bash
npm i dubnium@latest
```

## Update History <a href="#header" id="header"></a>

### v4.2.0 (4/10/2026)

* Added [`find()`](/4/core/get#find-record)
* Added `stopTTLMonitor()`&#x20;
* Added [Synchronization](/4/advanced/synchronization)
* Added [`lock()` and `unlock()`](/4/advanced/miscellaneous#lock-unlock)
* Added [`expire()`](/4/core/create#retroactively-set)
* Fixed `has()`

### v4.1.0 (3/4/2026)

* Added [`saveSnapshot()`](/4/advanced/versioning#manually-save-snapshot)
* Added [`restoreFromTrash()`](/4/core/delete#restore-from-trash)
* Added [TTL](/4/core/delete#monitor-ttls)
* Added [versions generator](/4/advanced/versioning#generator)
* Added [Metadata](/4/advanced/metadata)
* Added [Indexing](/4/advanced/indexing)
* Deprecated `getFromValue()`

### v4.0.0 (2/12/2026)

* Rewritten
* Most functions are now `async`
* Simplified overall project by removing unnecessary functions
  * Removed config files
  * Removed Extensions
* Split project into seperate files for better maintainability
* Added [Collections](/4/templates/collections)
* Added trashing
* Improved writing logic. Now uses [proper-lockfile](https://www.npmjs.com/package/proper-lockfile)


# Import

Dubnium Browser is available on Github and our website.

### Add to your site <a href="#npm" id="npm"></a>

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

```html
<script src="https://coolstone.dev/dubnium/browser/v0.js"></script>
```

{% endcode %}

### Add a different version

{% hint style="info" %}
Please note that only **major** versions will get a new file. The currently available versions are listed below

* v0
  {% endhint %}

```html
<script src="https://coolstone.dev/dubnium/browser/v{VERSION_HERE}.js"></script>
```

### Or download it from GitHub <a href="#github" id="github"></a>

{% embed url="<https://github.com/coolstone-tech/dubnium>" %}


# Overview

We recommend you read the full docs, but this will get you started with the basics.

## Initialize

{% hint style="info" %}
You can initialize as many databases as you want
{% endhint %}

{% code lineNumbers="true" %}

```javascript
const db = new Dubnium('type',temp)
```

{% endcode %}

## Make your first Record

{% code lineNumbers="true" %}

```javascript
db.create('tag', data)
```

{% endcode %}

## Get a Record

{% tabs %}
{% tab title="From Tag" %}
{% code lineNumbers="true" %}

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

{% endcode %}
{% endtab %}

{% tab title="From value" %}
{% code lineNumbers="true" %}

```javascript
db.getFromValue('key','value',returnType) //JSON Only
```

{% endcode %}

`returnType` info can be found [here](/browser/miscellaneous#returntype)
{% endtab %}

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

```javascript
db.getAll(returnType)
```

{% endcode %}

`returnType` info can be found [here](/browser/miscellaneous#returntype)
{% endtab %}
{% endtabs %}

## Delete a Record

{% code lineNumbers="true" %}

```javascript
db.get('tag').delete()
```

{% endcode %}

## Modify a Record

{% tabs %}
{% tab title="Data (JSON only)" %}
{% code lineNumbers="true" %}

```javascript
db.get('tag').setValue("key","new value")
```

{% endcode %}

For non-JSON, use [`overwrite()`](/browser/modify#overwrite)
{% endtab %}

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

```javascript
db.get("old_tag").setTag("new_tag")
```

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

### Check out our full docs for more API methods and in-depth explanations.


# Initialize

{% hint style="info" %}
You can initialize as many databases as you want
{% endhint %}

{% code lineNumbers="true" %}

```javascript
const db = new Dubnium('type',temp)
```

{% endcode %}

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>type</td><td>Data type. Options: <code>text</code> or <code>json</code></td><td>String</td><td>false</td></tr><tr><td>temp</td><td>If set to true, use <code>sessionStorage</code> instead of <code>localStorage</code></td><td>Bool</td><td>false</td></tr></tbody></table>


# Manage

## Create Record <a href="#create" id="create"></a>

{% code lineNumbers="true" %}

```javascript
db.create('tag',data)
```

{% endcode %}

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>tag</td><td>The new Record's tag</td><td>String</td><td>true</td></tr><tr><td>data</td><td>The new Record's data</td><td>String || object</td><td>true</td></tr></tbody></table>

## Delete Record <a href="#delete" id="delete"></a>

{% code lineNumbers="true" %}

```javascript
db.get('tag').delete()
```

{% endcode %}

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>tag</td><td>The tag of the Record to delete</td><td>String</td><td>true</td></tr></tbody></table>


# Get

## Get Record From Tag <a href="#from-tag" id="from-tag"></a>

{% code lineNumbers="true" %}

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

{% endcode %}

### Parameters

<table><thead><tr><th>Name</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></tbody></table>

## Get Record information <a href="#info" id="info"></a>

### Data

{% code lineNumbers="true" %}

```javascript
db.get('tag').data
```

{% endcode %}

### Tag <a href="#tag" id="tag"></a>

{% code lineNumbers="true" %}

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

{% endcode %}

## Get all Records <a href="#all" id="all"></a>

{% code lineNumbers="true" %}

```javascript
db.getAll(returnType)
```

{% endcode %}

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>returnType</td><td>Read about it <a href="/pages/GDKFlcVUpNS5ZIpXkKAH#returntype">here</a></td><td>Number</td><td>true</td></tr></tbody></table>

## Search Tags

{% code lineNumbers="true" %}

```javascript
db.searchTags('term',returnType)
```

{% endcode %}

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>term</td><td>The search term</td><td>String</td><td>true</td></tr><tr><td>returnType</td><td>Read about it <a href="/pages/GDKFlcVUpNS5ZIpXkKAH#returntype">here</a></td><td>Number</td><td>true</td></tr></tbody></table>

## Search Record Content <a href="#search-content" id="search-content"></a>

{% code lineNumbers="true" %}

```javascript
db.get("tag").search('query','splitBy')
```

{% endcode %}

### Search Object Keys (JSON Only) <a href="#search-keys" id="search-keys"></a>

{% code lineNumbers="true" %}

```javascript
db.searchKeys('query') // splitBy is not a param for the searchKeys method
```

{% endcode %}

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>query</td><td>Search query</td><td>String</td><td>true</td></tr><tr><td>splitBy</td><td>String to split the Record's data by. For example, \n for lines or " " for spaces. If not present, Dubnium will default to space.</td><td>String</td><td>true</td></tr></tbody></table>

## Get Record from Value (JSON Only) <a href="#from-value" id="from-value"></a>

{% code lineNumbers="true" %}

```javascript
db.getFromValue('key','value',returnType)
```

{% endcode %}

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>key</td><td>The key to get from</td><td>String</td><td>true</td></tr><tr><td>value</td><td>The value to get from</td><td>String</td><td>true</td></tr><tr><td>returnType</td><td>Read about it <a href="/pages/GDKFlcVUpNS5ZIpXkKAH#returntype">here</a></td><td>Number</td><td>true</td></tr></tbody></table>

## Check if a Record exists <a href="#exists" id="exists"></a>

Check if a record exists.

{% hint style="info" %}
This will only return `true` or `false`.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
db.exists('tag')
```

{% endcode %}

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>tag</td><td>The tag to check for</td><td>String</td><td>true</td></tr></tbody></table>


# Modify

## Modify Record Content (JSON Only) <a href="#content" id="content"></a>

{% code lineNumbers="true" %}

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

{% endcode %}

{% hint style="info" %}
For non-JSON, use [`overwrite()`](#overwrite)
{% endhint %}

### Parameters

<table><thead><tr><th>Name</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>key</td><td>The key to change</td><td>String</td><td>true</td></tr><tr><td>value</td><td>The value to set to</td><td>Any</td><td>true</td></tr></tbody></table>

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

{% hint style="warning" %}
Do not use this with JSON records.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
db.get('tag').append(data)
```

{% endcode %}

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

## Change the length of a Record <a href="#length" id="length"></a>

{% code lineNumbers="true" %}

```javascript
db.get('tag').truncate(start,end)
```

{% endcode %}

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>start</td><td>Index to start at</td><td>Number</td><td>true</td></tr><tr><td>end</td><td>Index to stop at</td><td>Number</td><td>true</td></tr></tbody></table>

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

{% code lineNumbers="true" %}

```javascript
db.get('tag').overwrite(data)
```

{% endcode %}

### Parameters

<table><thead><tr><th>Name</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>data</td><td>The data to overwrite with</td><td>Any (must match file extension)</td><td>true</td></tr></tbody></table>

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

{% code lineNumbers="true" %}

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

{% endcode %}

### Parameters

<table><thead><tr><th>Name</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>

## Overwrite Data from another Record <a href="#syncwith" id="syncwith"></a>

{% code lineNumbers="true" %}

```javascript
db.get('tag').syncWith('_tag')
```

{% endcode %}

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>_tag</td><td>The tag of the Record you want to get the data from.</td><td>String</td><td>true</td></tr></tbody></table>


# Templates

An easy way to keep your JSON records similar!

## Make a new Template <a href="#new" id="new"></a>

{% code lineNumbers="true" %}

```javascript
const template = new Template({
id:"",
name:"",
password:""
})
```

{% endcode %}

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>template</td><td>The object to base the new Template on.</td><td>Object</td><td>true</td></tr></tbody></table>

## Use Template <a href="#use" id="use"></a>

{% code lineNumbers="true" %}

```javascript
data.create('tag', template.use('123456',"John","password"))
```

{% endcode %}

### Parameters

The parameters of this function are what will be set to the value of the keys in order.

**Example**: the parameter`John` will be the value of `name`since they are both in the second position.

## Full code example <a href="#example" id="example"></a>

{% code lineNumbers="true" %}

```javascript
const data = new Dubnium('json' /* Templates are JSON only */,false) 

const template = new Template({ 
id:"",
name:"",
password:""
})

data.create('tag', template.use('123456',"John","password"))
```

{% endcode %}


# Miscellaneous

## To String & JSON

{% code lineNumbers="true" %}

```javascript
db.get('tag').toString() // returns data as string
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
db.get('tag').toJSON() // returns data as an object, if possible
```

{% endcode %}

### Parameters

None

## End

If you want to *end* a string of methods, you can with `.end()`. It emits the [`end`](broken://pages/WBwFyPsLkvPcUSpCbZ9i) event and no methods can be added after it. **Note: this is not required.**

{% code lineNumbers="true" %}

```javascript
db.get("tag").overwrite(data).end()
```

{% endcode %}

## Exit&#x20;

If you wish to exit the Record editor API, call the `exit()` method and it will return the class.

{% code lineNumbers="true" %}

```javascript
db.get('tag').overwrite(data).exit().//any_class_function
```

{% endcode %}

## Something missing? <a href="#other" id="other"></a>

Use the `custom()` method to run a custom function without leaving the Record Editor API.

{% code lineNumbers="true" %}

```javascript
db.get('tag').custom(record => {
//do anything here
})
```

{% endcode %}

We also have a `custom()` method on the Dubnium class.

{% code lineNumbers="true" %}

```javascript
db.custom(db_class => {
//do anything here
})
```

{% endcode %}

Or if you wish to have it added to the API, [tell us](https://github.com/coolstone-tech/dubnium/discussions)!

## returnType

### About <a href="#returntype-about" id="returntype-about"></a>

Some functions have the `returnType` parameter. The values accepted are `1` and `2`.&#x20;

### 1 <a href="#returntype-1" id="returntype-1"></a>

Return as **JSON**.

### **2** <a href="#returntype-2" id="returntype-2"></a>

Return as an **Array**.

{% code lineNumbers="true" %}

```javascript
db.getAll(1) // will return all the records as an {JSON: 'object'}
db.getAll(2) // will return all the records as an [Array]
```

{% endcode %}


# Update Log

Date format is MM/DD/YYYY

## Get the latest version <a href="#get" id="get"></a>

Dubnium for browser is automatically updated to the newest version

## Version 0 Update History <a href="#header" id="header"></a>

### v0.0.1

* Release


# Overview

We recommend you read the full docs, but this will get you started with the basics.

## Install&#x20;

Dubnium is available on npm or GitHub (requires Node.js) and is available for CommonJS and ECMAScript modules.

### Download it from npm <a href="#npm" id="npm"></a>

{% hint style="info" %}
We strongly recommend using npm.
{% endhint %}

```bash
npm i dubnium
```

Check out our [npm page](https://npmjs.com/dubnium).

### Or download it from GitHub <a href="#github" id="github"></a>

<https://github.com/coolstone-tech/dubnium>

## Initialize

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

```javascript
const Dubnium = require('dubnium') 
const db = new Dubnium('dirPath','ext')
```

{% endcode %}
{% endtab %}

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

```javascript
import Dubnium from 'dubnium'
const db = new Dubnium('dirPath','ext')
```

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

## Make your first Record

{% code lineNumbers="true" %}

```javascript
db.create('tag', content)
```

{% endcode %}

## Get a Record

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

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

{% endcode %}
{% endtab %}

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

```javascript
db.getAll()
```

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

## Delete a Record

{% code lineNumbers="true" %}

```javascript
db.get('tag').delete()
```

{% endcode %}

## Modify a Record

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

{% code lineNumbers="true" %}

```javascript
db.get('tag').edit("new_content")
```

{% endcode %}
{% endtab %}

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

```javascript
db.get("old_tag").setTag("new_tag")
```

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

#### Check out our full docs for more API methods and in-depth explanations.


# Initialize

How to get started with Dubnium.

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

```javascript
const Dubnium = require('dubnium')
const db = new Dubnium('dirPath', 'ext', options)
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
const db = new (require("dubnium"))("dir", "ext", options)
```

{% endcode %}
{% endtab %}

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

```javascript
import Dubnium from 'dubnium'
const db = new Dubnium('dirPath','ext', options)
```

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

{% hint style="info" %}
You can initialize as many databases as you want
{% endhint %}

### Parameters

<table><thead><tr><th width="197">Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>dirPath</td><td>The path to the directory to store Records.</td><td>String</td><td>true</td></tr><tr><td>ext</td><td>Custom file extension (default: <code>json</code>) </td><td>String</td><td>false</td></tr><tr><td>options</td><td>Options</td><td>Object</td><td>false</td></tr><tr><td>options.name</td><td>Database name</td><td>String</td><td>false</td></tr><tr><td>options.force</td><td>Enable force overwriting of a preexisting Record.</td><td>Boolean</td><td>false</td></tr><tr><td>options.preserveConfig</td><td>Set to <code>false</code> to not overwrite the config file</td><td>Boolean</td><td>false</td></tr><tr><td>options.versioning</td><td>Read more in <a href="/pages/3HHPjwUPXgwBXF68CseI">Versioning</a>.</td><td>Object</td><td>false</td></tr><tr><td>options.requireRoot</td><td>Functions to require root access to run</td><td>Array</td><td>false</td></tr><tr><td>options.template</td><td>Require all new JSON Records to follow a template, or Dubnium will throw an error</td><td><a href="/pages/JfgEEJMNrNiS1ARLcY2K">Template</a></td><td>false</td></tr></tbody></table>


# Manage

How to create & delete Records.

## Create Record <a href="#create" id="create"></a>

{% tabs %}
{% tab title="In database" %}
{% code lineNumbers="true" %}

```javascript
db.create('tag', content, options)
```

{% 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>The new Record's tag</td><td>String</td><td>true</td></tr><tr><td>content</td><td>The Record's content</td><td>Any</td><td>true</td></tr><tr><td>options</td><td>writeFile options</td><td>String || Object</td><td>false</td></tr></tbody></table>
{% endtab %}

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

```javascript
const { Record } = require("dubnium")
Record( tag:"tag", dir:"./data", ext:"json", content )
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>dir</td><td>Dir to create in</td><td>String</td><td>true</td></tr><tr><td>tag</td><td>Record's tag</td><td>String</td><td>true</td></tr><tr><td>content</td><td>Record content</td><td>Any</td><td>true</td></tr><tr><td>ext</td><td>File extension</td><td>String</td><td>false</td></tr></tbody></table>

If `ext` is not specified, it will default to `json`
{% endtab %}

{% tab title="From File" %}

```javascript
db.create('tag', path, options)
```

<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 new Record's tag</td><td>String</td><td>true</td></tr><tr><td>path</td><td>Path to get content from</td><td>String</td><td>true</td></tr><tr><td>options</td><td>writeFile options</td><td>String || object</td><td>false</td></tr></tbody></table>
{% endtab %}

{% tab title="Clone" %}

```javascript
db.get('tag').clone('target')
```

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>target</td><td>Target directory to clone the record in.</td><td>String</td><td>true</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

## Delete Record <a href="#delete" id="delete"></a>

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

```javascript
db.get('tag').delete()
```

{% endcode %}
{% endtab %}

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

```javascript
db.delete('tag')
```

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

### Close

Delete **all** records & the directory

{% code lineNumbers="true" %}

```javascript
db.close()
```

{% endcode %}

### Wipe

Delete **all** records & *preserve* the directory

{% code lineNumbers="true" %}

```javascript
db.wipe()
```

{% endcode %}

### Delete Old Records

{% code lineNumbers="true" %}

```javascript
db.deleteOld({ ms:5, seconds:5, minutes:5, hours:5, days:0})
```

{% endcode %}

Requires at least one of the options below (multiple options will stack)

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-hidden data-type="checkbox">Required</th></tr></thead><tbody><tr><td>ms</td><td>Milliseconds</td><td>Number</td><td>false</td></tr><tr><td>seconds</td><td>Seconds</td><td>Number</td><td>false</td></tr><tr><td>minutes</td><td>Minutes</td><td>Number</td><td>false</td></tr><tr><td>hour</td><td>Hours</td><td>Number</td><td>false</td></tr><tr><td>days</td><td>Days</td><td>Number</td><td>false</td></tr></tbody></table>

### Delete Large Records

{% code lineNumbers="true" %}

```javascript
db.deleteLarge({ bytes:0, kilobytes:0, megabytes:0, gigabytes:0 })
```

{% endcode %}

Requires at least one of the options below (multiple options will stack)

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-hidden data-type="checkbox">Required</th></tr></thead><tbody><tr><td>options.bytes</td><td>Bytes</td><td>Number</td><td>false</td></tr><tr><td>options.kilobytes</td><td>Kilobytes</td><td>Number</td><td>false</td></tr><tr><td>options.megabytes</td><td>Megabytes</td><td>Number</td><td>false</td></tr><tr><td>options.gigabytes</td><td>Gigabytes</td><td>Number</td><td>false</td></tr></tbody></table>


# Get

How to get Record content and information.

## Get Record From Tag <a href="#from-tag" id="from-tag"></a>

{% code lineNumbers="true" %}

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

{% 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>The Record's tag</td><td>String</td><td>true</td></tr></tbody></table>

## Get Record Information <a href="#info" id="info"></a>

### Content <a href="#content" id="content"></a>

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

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

{% endcode %}
{% endtab %}

{% tab title="Read" %}

```javascript
db.read('tag')
```

{% endtab %}
{% endtabs %}

### Path <a href="#path" id="path"></a>

{% tabs %}
{% tab title="Path property" %}
{% code lineNumbers="true" %}

```javascript
db.get('tag').path
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
db.get('tag').realpath
```

{% endcode %}
{% endtab %}

{% tab title="Locate method" %}
{% code lineNumbers="true" %}

```javascript
db.locate('tag', realpath)
```

{% 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's tag</td><td>string</td><td>true</td></tr><tr><td>realpath</td><td>Return realpath</td><td>bool</td><td>false</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### Tag <a href="#tag" id="tag"></a>

{% code lineNumbers="true" %}

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

{% endcode %}

## Get Database Name <a href="#all" id="all"></a>

{% hint style="info" %}
Names are derived from the directory's base name or can manually be set in config object when initializing.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
db.name
```

{% endcode %}

## Get Record from Value <a href="#from-value" id="from-value"></a>

{% hint style="warning" %}
This checks if the record content is exactly the `value` param
{% endhint %}

{% code lineNumbers="true" %}

```javascript
db.getFromValue('value')
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>value</td><td>The value to get from</td><td>String</td><td>true</td></tr><tr><td>exact</td><td>Exact match?</td><td>Boolean</td><td>false</td></tr></tbody></table>

### Get from Key/Value pair

{% hint style="danger" %}

### JSON Only

This function iterates all records to find any with the matching key/value pair you provided.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
db.getFromKeyValue('key', 'value', exact)
```

{% endcode %}

## Check if a Record exists <a href="#exists" id="exists"></a>

{% hint style="info" %}
This will only return `true` or `false`.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
db.has('tag')
```

{% 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>The tag to check for</td><td>String</td><td>true</td></tr></tbody></table>

## Get All Records

```javascript
db.getAll({tagOnly:false, limit:10, filter})
```

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>options.tagOnly</td><td>Set to true to return an array of tags instead of Records</td><td>Boolean</td><td>false</td></tr><tr><td>options.limit</td><td>Max results</td><td>Number</td><td>false</td></tr><tr><td>options.filter</td><td>Filter results</td><td>Function</td><td>false</td></tr></tbody></table>


# Edit

How to edit Record content and attributes.

## Save Content <a href="#content" id="content"></a>

{% code lineNumbers="true" %}

```javascript
const record = db.get('tag')
record.content.KEY = "VALUE"
// or record.content = "VALUE"
record.save()
```

{% endcode %}

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

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

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

{% endcode %}
{% endtab %}

{% tab title="Prepend" %}

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

{% 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
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
db.get('tag').edit(content)
```

{% endcode %}
{% endtab %}

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

```javascript
db.edit("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>

## Modify a Key

{% hint style="danger" %}

### JSON Only

This function only modifies objects.
{% endhint %}

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

<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</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
db.get('old_tag').setTag('new_tag')
```

{% endcode %}
{% endtab %}

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

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

## Overwrite from another Record <a href="#syncwith" id="syncwith"></a>

{% code lineNumbers="true" %}

```javascript
db.get('tag').syncWith('_tag')
```

{% 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>The tag of the Record you want to get the content from.</td><td>String</td><td>true</td></tr></tbody></table>

## Beautify JSON

{% hint style="danger" %}

### JSON Only

This function only modifies objects.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
db.get('tag').beautify(replacer, space)
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>replacer</td><td>A function that transforms the results.</td><td>Function</td><td>false</td></tr><tr><td>space</td><td>Adds indentation, white space, and line break characters to the return-value to make it easier to read. Default: 2</td><td>Number</td><td>false</td></tr></tbody></table>

## Empty Record

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

{% code lineNumbers="true" %}

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

{% endcode %}

### Check if a Record is empty

{% code lineNumbers="true" %}

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

{% endcode %}


# Search

How to search your database.

## Search Tags

{% code lineNumbers="true" %}

```javascript
db.list({filter:() => e.tag == "TAG", limit:10})
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>options.filter</td><td>Filter function</td><td>Function</td><td>false</td></tr><tr><td>options.limit</td><td>Max results</td><td>Number</td><td>false</td></tr></tbody></table>

## Search all Records by Content

{% code lineNumbers="true" %}

```javascript
db.getFromValue('query', limit)
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>query</td><td>Query to search for</td><td>String</td><td>true</td></tr><tr><td>limit</td><td>Max results</td><td>Number</td><td>false</td></tr></tbody></table>

## Search Content

{% tabs %}
{% tab title="Search" %}
Convert content to String and return the result of [`String.search()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)

{% code lineNumbers="true" %}

```javascript
db.get("tag").search('query')
```

{% endcode %}
{% endtab %}

{% tab title="Search As Array" %}
{% hint style="danger" %}
This function is deprecated
{% endhint %}

Have Dubnium split the content by a character and then search the array.

{% code lineNumbers="true" %}

```javascript
db.get('tag').searchAsArray('query', 'splitBy')
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td><p></p><p>splitBy</p></td><td>String to split the Record's content by. For example, \n for lines or " " for spaces. If not present, Dubnium will default to space.</td><td>String</td><td>false</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### Search Object Keys <a href="#search-keys" id="search-keys"></a>

{% hint style="danger" %}

### JSON Only <a href="#search-keys" id="search-keys"></a>

This function searches object keys only.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
db.get('tag').searchKeys('query')
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>query</td><td>The search query</td><td>String</td><td>true</td></tr></tbody></table>


# Miscellaneous

Other functions provided by Dubnium.

## Directory

### Change <a href="#change-dir" id="change-dir"></a>

{% code lineNumbers="true" %}

```javascript
db.config.dir = './new/dir'
```

{% endcode %}

### Make <a href="#make-dir" id="make-dir"></a>

{% code lineNumbers="true" %}

```javascript
db.dir()
```

{% endcode %}

### Get path <a href="#get-dir" id="get-dir"></a>

{% code lineNumbers="true" %}

```
db.dirPath
```

{% endcode %}

### Iterate

{% code lineNumbers="true" %}

```javascript
db.iterate(record => {})
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>callback</td><td>Callback</td><td>function</td><td>true</td></tr></tbody></table>

## Create Symlink to a Record <a href="#create-symlink" id="create-symlink"></a>

{% code lineNumbers="true" %}

```javascript
db.get('tag').symlink('./path/to/symlink') 
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>target</td><td>Path to a directory where the symlink will be created</td><td>String</td><td>true</td></tr></tbody></table>

## Get Record's Stats <a href="#get-stats" id="get-stats"></a>

{% code lineNumbers="true" %}

```javascript
db.get('tag').stats
```

{% endcode %}

## Content to String & JSON

{% code lineNumbers="true" %}

```javascript
db.get('tag').toString() // returns content as string
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
db.get('tag').toJSON() // returns content as an object, if possible
```

{% endcode %}

## End

If you want to *end* a string of methods, you can with `.end()`. It emits the [`end`](/3/events) event and no methods can be added after it. **Note: this is not required.**

{% code lineNumbers="true" %}

```javascript
db.get("tag").overwrite(content).end()
```

{% endcode %}

## Exit&#x20;

If you wish to exit the Record editor API, call the `exit()` method and it will return the class.

{% code lineNumbers="true" %}

```javascript
db.get('tag').overwrite(content).exit().//any_class_function
```

{% endcode %}

## FS

Run any `fs` method on the Record or database.

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

```javascript
db.fs('methodName', ...method_args)
```

{% endcode %}
{% endtab %}

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

```javascript
db.get('tag').fs('methodName', ...method_args)
```

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

## Execute Bash <a href="#bash" id="bash"></a>

{% code lineNumbers="true" %}

```javascript
db.exec('command', (error, stdout) => {})
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>command</td><td>The command (include arguments)</td><td>string</td><td>true</td></tr><tr><td>callback</td><td>Callback</td><td>function</td><td>true</td></tr></tbody></table>

## Internal Functions

Dubnium exports some internal functions that can be used in your project.

{% code lineNumbers="true" %}

```javascript
require('dubnium/functions')
```

{% endcode %}

## Aliases

Don't like the name we chose for a method? Set an alias!&#x20;

{% code lineNumbers="true" %}

```javascript
db.alias('alais_here', 'existing_function')
```

{% endcode %}

For example,

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

```javascript
db.alias('val', 'getFromValue') // Allows you to call db.val() instead of db.getFromValue()
```

{% endcode %}


# Middleware

Dubnium has built-in Express middleware functions to manage Records. Data is never sent to the client without your permission.

## Parameters

{% hint style="info" %}
If `tag.key` or `content.key` is omitted, the `from` value is used.
{% endhint %}

<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>First param to set tag info.</td><td>Object</td><td>true</td></tr><tr><td>tag.from</td><td>Part of the <code>req</code> object to get the tag from (e.g. <code>headers</code> or <code>body</code>)</td><td>String</td><td>true</td></tr><tr><td>tag.key</td><td>Key from the <code>from</code> object to get tag from.</td><td>String</td><td>false</td></tr><tr><td>content</td><td>Second param to set content info</td><td>Object</td><td>true</td></tr><tr><td>content.from</td><td>Part of the <code>req</code> object to get the content from (e.g. <code>headers</code> or <code>body</code>)</td><td>String</td><td>true</td></tr><tr><td>content.key</td><td>Key from the <code>from</code> object to get tag from.</td><td>String</td><td>false</td></tr></tbody></table>

## Methods

### Create

{% code lineNumbers="true" %}

```javascript
app.get('/new', db.middleware.create({ from:"query", key:"tag" }, { from:"query", key:"content" }), (req, res) => {
// Creates a record with the tag and content from the query
})
```

{% endcode %}

### Get

```javascript
app.get('/:tag', db.middleware.get({ from:"params", key:"tag" }), (req, res) => {
// Access the record directly from req.record, if it exists
})
```

### DB

{% code lineNumbers="true" %}

```javascript
app.get('/db', db.middleware.db(), (req, res) => {
// Access the database directly from req.db
})
```

{% endcode %}

### Delete

{% code lineNumbers="true" %}

```javascript
app.get('/', db.middleware.delete({ from:"headers", key:"id" }), (req, res) => {
    res.send('Account deleted.')
})
```

{% endcode %}

### Edit

```javascript
app.get('/', db.middleware.edit({ from:"body" }, { from:"content" }), (req, res) => {
    res.send('Account edited!')
})
```

### Other

```javascript
app.get('/', db.middleware.other('function', ...args), (req, res) => {
    res.send(`Ran ${req.db.function} with args ${req.db.args}`)
    // req.db['function'] is the requested function
    // req.db.function is the name of the requested function
    // req.db.args is the requested args
    // req.db.result is the result of the function
})
```

## Full Example

{% code title="middleware.js" lineNumbers="true" %}

```javascript
const { Dubnium } = require('./v3')
const express = require('express')
const app = express()

const db = new Dubnium('./test_db', 'txt')

const c_m = db.middleware.create({ from:"query", key:"tag" }, { from:"query", key:"content" })
const g_m = db.middleware.get({ from:"params", key:"tag" })
const db_m = db.middleware.db()

app.get('/new', c_m, (req, res) => {
// Creates a record with the tag and content from the query
})

app.get('/:tag', g_m, (req, res) => {
// Access the record directly from req.record, if it exists
})

app.get('/db', db_m, (req, res) => {
// Access the database directly from req.db
})

app.listen(3000, () => {
    console.log('Example app listening on port 3000!')
})
```

{% endcode %}


# Versioning

Dubnium has 2 options to save Record versions.

## 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 %}


# JSON

## Make a new Template <a href="#new" id="new"></a>

{% hint style="info" %}
Set any value to `required` to require that value to be set.
{% endhint %}

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

```javascript
const { Dubnium, Template } = require('dubnium') // require('dubnium') is an alias of require('dubnium').Dubnium
const template = new Template({
id:"required",
name:"",
password:"required"
})
```

{% endcode %}
{% endtab %}

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

```javascript
import { Dubnium, Template } from 'dubnium'
const template = new Dubnium.Template({
id:"",
name:"",
password:""
})
```

{% 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>template</td><td>The object to base the new Template on.</td><td>Object</td><td>true</td></tr></tbody></table>

## Use Template <a href="#use" id="use"></a>

{% code lineNumbers="true" %}

```javascript
database.create('tag', template.use('123456',"John","password"))
```

{% endcode %}

The parameters of this function are what will be set to the value of the keys in order.

**Example**: the parameter`John` will be the value of `name`since they are both in the second position.

## Full code example <a href="#example" id="example"></a>

{% code title="json\_template.js" lineNumbers="true" %}

```javascript
const { Dubnium, Template } = require('dubnium')
// import { Dubnium, Template } from 'dubnium' // for ESM
const database = new Dubnium('./db','json') // Initialize a database

const template = new Template({ // Make a new Template
id:"",
name:"",
password:""
})

database.create('tag', template.use('123456',"John","password")) // Create a Record based on the Template
```

{% endcode %}


# String

## Make a new Template <a href="#new" id="new"></a>

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

```javascript
const { Dubnium, Template } = require('dubnium') // require('dubnium') is an alias of require('dubnium').Dubnium
const template = new Template("Hello, {0}")
```

{% endcode %}
{% endtab %}

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

```javascript
import { Dubnium, Template } from 'dubnium'
const template = new Template("Hello, {0}", TemplateTypes.STRING)
```

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

## Use Template <a href="#use" id="use"></a>

{% code lineNumbers="true" %}

```javascript
database.create('tag', template.use("World"))
```

{% endcode %}

The parameters of this function determine the index's value in the string.

**Example**: the parameter `0` will be the value of `World` since they are both at index 0.

## Full code example <a href="#example" id="example"></a>

{% code title="string\_template.js" lineNumbers="true" %}

```javascript
const { Dubnium, Template } = require('dubnium')
// import { Dubnium, Template } from 'dubnium' // for ESM
const database = new Dubnium('./db', 'txt') // Initialize a database

const template = new Template("Hello, {0}") // Make a new Template

database.create('tag', template.use('World')) // Create a Record based on the Template
```

{% endcode %}


# Setup

### 1. Find an extension.

For this guide, we will use a custom function. You can find one on your own, or use our [Extension Finder](https://coolstone.dev/dubnium/extensions/).

{% code title="createHelloWorld.js" lineNumbers="true" %}

```javascript
(db) => {
if(!db) throw new Error("This extension requires database permissions")
db.create('hello', `Hello, World!`)
}
```

{% endcode %}

### 2. Define permissons

{% code lineNumbers="true" %}

```javascript
const { extensionPermissions } = require('dubnium')
const permissions = new extensionPermissions(true, false, [ 'edit' ]) 
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>record</td><td>Allow access to the Record when extending the record editor API</td><td>true</td></tr><tr><td>database</td><td>Allow access to the entire database when extending the database.</td><td>true</td></tr><tr><td>filterList</td><td>An array of function names to omit from an extension.</td><td>false</td></tr></tbody></table>

### 3. Add to Dubnium

{% code lineNumbers="true" %}

```javascript
db.extend('name', require('./extension'), permissions)
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
db.get('tag').extend('name', require('./extension'), permissions)
```

{% endcode %}

### 4. Use the extension

{% code lineNumbers="true" %}

```javascript
db.name()
```

{% endcode %}

### Full Example

{% code title="createHelloWorld.js" lineNumbers="true" %}

```javascript
db.extend('createHelloWorld', (db) => {
if(!db) throw new Error("This extension requires database permissions")
db.create('hello', `Hello, World!`)
}, new extensionPermissions(false, true))

db.createHelloWorld()
```

{% endcode %}


# Create

## Create

If you want to create a Plugin to publish on NPM, copy the code below and put the source in the exported method.

{% hint style="info" %}
Write your plugins in Commonjs to allow either Commonjs or ESM support!
{% endhint %}

{% code title="new\_extension.js" overflow="wrap" lineNumbers="true" %}

```javascript
module.exports = (database, record) => {
// database & record can be null, depending on the permissions. Be sure to be able to handle that!
}
```

{% endcode %}

## Publish

If you want to add it to our Extension Finder, publish it to npm with `dubnium` as a keyword.


# CLI

Run Dubnium functions from your command-line!

## Install

### Install in your project

```bash
npm i dubnium@latest
```

### Install globally

```bash
sudo npm i dubnium@latest -g
```

## Use

If you installed it [globally](#install-globally)

```bash
dubnium <command>
```

If you installed it [in your project](#install-in-your-project)

```bash
npx dubnium <command>
```

### Commands

Commands are **similar** to the API. If you want to call a function on a Record, do **not** put `get().func()`. Instead, make the command just `func` and put the Record's tag as the first arg when prompted.

### Example

![](/files/GPi9ilO2XHRwf6BMak1k)

The CLI will ask for a few values, and then the method will be run and the return value is logged to the console.

## Invoke Programmatically

{% hint style="warning" %}
Make sure the command is present when you run the file.

```bash
node index.js <command>
```

{% endhint %}

{% code lineNumbers="true" %}

```javascript
require("dubnium/cli")
```

{% endcode %}


# Events

Dubnium uses the built-in Events module to send messages when something happens!

| Event            | Callback Arguments              | About                                                                               |
| ---------------- | ------------------------------- | ----------------------------------------------------------------------------------- |
| start            | Directory path & file extension | Fires when Dubnium is initialized.                                                  |
| create           | Tag & content                   | Fires when a Record is created.                                                     |
| delete           | Tag & content                   | Fires when a Record is deleted.                                                     |
| edit             | Tag, old & new content          | Fires when a Record's value changes.                                                |
| retagged         | Old & new tag                   | Fires when a Record's tag changes.                                                  |
| wipe             | Directory path                  | Fires when the database is wiped.                                                   |
| close            | Directory path                  | Fires when the database is closed.                                                  |
| delete\_old      | Options                         | Fires when `deleteOld` is called. (Will also fire `delete` for any Records deleted) |
| dir              | Directroy path                  | Fires when the directory is created.                                                |
| move             | Tag, old & new directory        | Fires when a Record is moved.                                                       |
| clone            | Tag, target                     | Fires when a Record is cloned.                                                      |
| symlink          | Tag & path to symlink           | Fires when a Symlink is created.                                                    |
| sync             | Tag & tag of synced with        | Fires when `syncWith` is called.                                                    |
| delete\_large    | Options                         | Fires when [`deleteLarge()`](/3/api/manage#delete-large-records) is called.         |
| append           | Tag, content                    | Fires when content is appended.                                                     |
| truncate         | Tag, length                     | Fires when a Record is truncated.                                                   |
| fs               | Function, tag, args             | Fires when [`fs()`](/3/api/miscellaneous#fs) is called.                             |
| beautify         | Tag, replacer, space            | Fires when JSON is beautified.                                                      |
| exec             | Command & callback              | Fires when a bash command is ran via [`db.exec()`](/3/api/miscellaneous#bash).      |
| save             | Tag & content                   | Fires when a record is saved. This will also fire the `edit` event.                 |
| stop\_versioning | Options                         | Fires when you stop recording versions.                                             |
| empty            | Record tag                      | Fires when a Record is emptied.                                                     |

{% hint style="info" %}
Any events from `fs.watch()` will be fired if [versioning](/3/api/versioning) is enabled.
{% endhint %}

### Example

{% code lineNumbers="true" %}

```javascript
db.on('create', (tag, content) => { console.log(`${tag} was created!`) })
```

{% endcode %}


# Update Log

Date format is MM/DD/YYYY

## Get the latest version <a href="#get" id="get"></a>

{% tabs %}
{% tab title="Update" %}
Already have Dubnium in your project? Update it!

```bash
npm update dubnium
```

{% endtab %}

{% tab title="Install" %}
Want to get started using Dubnium in your projects? Install it!

```bash
npm i dubnium@latest
```

{% endtab %}
{% endtabs %}

## Update History <a href="#header" id="header"></a>

### v3.0.3 (2/11/2024)

* Fixed `getAll()`

### v3.0.2 (2/3/2024)

* Bug fixes
* Helper functions are now exported at `require('dubnium').Helpers`
* Deprecated `filter()`
* New `exact` parameter for [`getFromValue()`](/3/api/get#from-value) &[ ](#user-content-fn-1)[^1][`getFromKeyValue()`](/3/api/get#get-from-key-value-pair)
* Added `DubniumTemplateError` for template-related errors
* Limits for search queries. These are optional. Set to `0` to not limit.
* Added `tagOnly` param to [`getAll()`](/3/api/get#get-all-records) to easily get an array of Tags. `list()` was also added as a shorthand way to do this.
* [`isEmpty`](/3/api/edit#check-if-a-record-is-empty) is now a property, not a function
* Fixed functions that rely on `walkDir()`
* Added `requireRoot` config parameter
* Added [`modify()`](/3/api/edit#modify-a-key)
* Added `required` to [JSON Templates](/3/templates/json)
* Added `template` config parameter

### v3.0.1 (05/20/2023)

* Fixed a lot of issues
* Get, delete, edit, change tag, by a Record's index. Set the `tag` parameter to the index.
* Removed `createFromFile()`. Set content to a string containing the path to an existing file to create from a file. Set `options.notFromFile` to skip this.
* Added extension [filter lists](https://db.coolstone.dev/3/pages/TkdFc8Kbpc8HBkDGELNX#2.-define-permissons).
* Added [`read()`](/3/api/get#read)

### v3.0.0 (05/07/2023)

* Basic Record Editor API methods are now exported at the database level. (eg: `db.delete()`)
* Bug fixes & rewritten
* Extensions (removed plugins)
* Config is now stored in `/.dubnium/config.json`
* Function aliases
* Removed `returnType`, all return arrays now
* Added[`beautify()`](/3/api/edit#beautify-json)
* Added [`save()`](/3/api/edit#content)
* overwrite is now [`edit()`](/3/api/edit#overwrite)
* Added [`getFromKeyValue()`](/3/api/get#get-from-key-value-pair), and modified [`getFromValue()`](/3/api/get#from-value)
* [Middleware](/3/api/middleware)
* [Versioning](/3/api/versioning)
* New/revised [events](/3/events)
* \+ more

[^1]:


# Install

Dubnium is available on NPM or Github (requires Node.js) and is available for Commonjs and ESM.

### Download it from NPM <a href="#npm" id="npm"></a>

{% hint style="info" %}
We strongly recommend using NPM
{% endhint %}

```bash
npm i dubnium@2.3.1
```

Check out our [NPM page](https://npmjs.com/dubnium)

### Or download it from GitHub <a href="#github" id="github"></a>

{% embed url="<https://github.com/coolstone-tech/dubnium>" %}


# Overview

We recommend you read the full docs, but this will get you started with the basics.

## Initialize

{% hint style="info" %}
You can initialize as many databases as you want
{% endhint %}

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

```javascript
const Dubnium = require('dubnium') 
const db = new Dubnium('dirPath','ext', useConfig)
```

{% endcode %}
{% endtab %}

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

```javascript
import Dubnium from 'dubnium'
new Dubnium('dirPath','ext')
```

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

## Make your first Record

{% code lineNumbers="true" %}

```javascript
db.create('tag', content)
```

{% endcode %}

## Get a Record

{% tabs %}
{% tab title="From Tag" %}
{% code lineNumbers="true" %}

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

{% endcode %}
{% endtab %}

{% tab title="From value" %}
{% code lineNumbers="true" %}

```javascript
db.getFromValue('key','value',returnType) //JSON Only
```

{% endcode %}

`returnType` info can be found [here](/2/miscellaneous#returntype)
{% endtab %}

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

```javascript
db.getAll(returnType)
```

{% endcode %}

`returnType` info can be found [here](/2/miscellaneous#returntype)
{% endtab %}
{% endtabs %}

## Delete a Record

{% code lineNumbers="true" %}

```javascript
db.get('tag').delete()
```

{% endcode %}

## Modify a Record

{% tabs %}
{% tab title="Data (JSON only)" %}
{% code lineNumbers="true" %}

```javascript
db.get('tag').setValue("key","new value")
```

{% endcode %}

For non-JSON, use [`overwrite()`](/2/modify#overwrite)
{% endtab %}

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

```javascript
db.get("old_tag").setTag("new_tag")
```

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

#### Check out our full docs for more API methods and in-depth explanations.


# Initialize

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

```javascript
const { Dubnium } = require('dubnium') // const dubnium = require('dubnium') works as well.
const db = new Dubnium('dirPath','ext', useConfig)
```

{% endcode %}

or

{% code lineNumbers="true" %}

```javascript
const db = new (require("dubnium"))("dirPath","ext")
```

{% endcode %}
{% endtab %}

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

```javascript
import Dubnium from 'dubnium'
const db = new Dubnium('dirPath','ext', useConfig)
```

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

{% hint style="info" %}
You can initialize as many databases as you want
{% endhint %}

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>dirPath</td><td>The path to the directory to store Records.</td><td>string</td><td>true</td></tr><tr><td>ext</td><td>Custom file extension (default: <code>json</code>) </td><td>string</td><td>false</td></tr><tr><td>useConfig</td><td>Use config file (default: <code>true</code>)</td><td>bool</td><td>false</td></tr></tbody></table>


# Manage

## Create Record <a href="#create" id="create"></a>

{% tabs %}
{% tab title="In database" %}
{% code lineNumbers="true" %}

```javascript
db.create('tag',content,options)
```

{% 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>The new Record's tag</td><td>String</td><td>true</td></tr><tr><td>content</td><td>The Record's content</td><td>Any</td><td>true</td></tr><tr><td>options</td><td>writeFile options</td><td>Object</td><td>false</td></tr></tbody></table>
{% endtab %}

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

```javascript
const { Record } = require("dubnium")
Record({ tag:"tag", dir:"./data", ext:"json", content })
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>config.tag</td><td>Record's tag</td><td>String</td><td>true</td></tr><tr><td>config.dir</td><td>Dir to create in</td><td>String</td><td>true</td></tr><tr><td>config.ext</td><td>File extension</td><td>String</td><td>false</td></tr><tr><td>config.content</td><td>Record content</td><td>Any</td><td>true</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

## Delete Record <a href="#delete" id="delete"></a>

{% code lineNumbers="true" %}

```javascript
db.get('tag').delete()
```

{% endcode %}

No parameters

### Close

Delete **all** records & the directory

{% code lineNumbers="true" %}

```javascript
db.close()
```

{% endcode %}

No parameters

### Wipe

Delete **all** records & *preserve* the directory

{% code lineNumbers="true" %}

```javascript
db.wipe()
```

{% endcode %}

No parameters

### Delete Old Records

{% code lineNumbers="true" %}

```javascript
db.deleteOld({ ms:5, seconds:5, minutes:5, hours:5, days:0})
```

{% endcode %}

Requires at least one of the options below (multiple options will stack)

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>ms</td><td>Milliseconds</td><td>Number</td><td>false</td></tr><tr><td>seconds</td><td>Seconds</td><td>Number</td><td>false</td></tr><tr><td>minutes</td><td>Minutes</td><td>Number</td><td>false</td></tr><tr><td>hour</td><td>Hours</td><td>Number</td><td>false</td></tr><tr><td>days</td><td>Days</td><td>Number</td><td>false</td></tr></tbody></table>

### Delete Large Records

{% code lineNumbers="true" %}

```javascript
db.deleteLarge({ bytes:0, kilobytes:0, megabytes:0, gigabytes:0 })
```

{% endcode %}

Requires at least one of the options below (multiple options will stack)

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>options.bytes</td><td>Bytes</td><td>Number</td><td>false</td></tr><tr><td>options.kilobytes</td><td>Kilobytes</td><td>Number</td><td>false</td></tr><tr><td>options.megabytes</td><td>Megabytes</td><td>Number</td><td>false</td></tr><tr><td>options.gigabytes</td><td>Gigabytes</td><td>Number</td><td>false</td></tr></tbody></table>


# Get

## Get Record From Tag <a href="#from-tag" id="from-tag"></a>

{% code lineNumbers="true" %}

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

{% 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>The Record's tag</td><td>String</td><td>true</td></tr></tbody></table>

## Get Record information <a href="#info" id="info"></a>

### Content <a href="#content" id="content"></a>

{% hint style="info" %}
Data was renamed to content in [v2.3.0](https://db.coolstone.dev/2/pages/8fjUpBuaVKG4OjhjbotJ#v2.3.0-09-03-2022)
{% endhint %}

{% code lineNumbers="true" %}

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

{% endcode %}

### Path <a href="#path" id="path"></a>

{% tabs %}
{% tab title="Path property" %}
{% code lineNumbers="true" %}

```javascript
db.get('tag').path
```

{% endcode %}

<pre class="language-javascript" data-line-numbers><code class="lang-javascript"><strong>db.get('tag').realpath
</strong></code></pre>

{% endtab %}

{% tab title="Find method" %}
{% code lineNumbers="true" %}

```javascript
db.find('tag', realpath)
```

{% 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's tag</td><td>string</td><td>true</td></tr><tr><td>realpath</td><td>Return realpath</td><td>bool</td><td>false</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### Tag <a href="#tag" id="tag"></a>

{% code lineNumbers="true" %}

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

{% endcode %}

## Get Database name <a href="#all" id="all"></a>

{% code lineNumbers="true" %}

```javascript
db.name
```

{% endcode %}

## Get all Records <a href="#all" id="all"></a>

{% code lineNumbers="true" %}

```javascript
db.getAll(returnType)
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>returnType</td><td>Read about it <a href="/pages/GDKFlcVUpNS5ZIpXkKAH#returntype">here</a></td><td>Number</td><td>true</td></tr></tbody></table>

## Search Tags

{% code lineNumbers="true" %}

```javascript
db.searchTags('term',returnType)
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>term</td><td>The search term</td><td>String</td><td>true</td></tr><tr><td>returnType</td><td>Read about it <a href="/pages/GDKFlcVUpNS5ZIpXkKAH#returntype">here</a></td><td>Number</td><td>true</td></tr></tbody></table>

## Search Record Content <a href="#search-content" id="search-content"></a>

{% code lineNumbers="true" %}

```javascript
db.get("tag").search('query','splitBy')
```

{% endcode %}

### Search Object Keys (JSON Only) <a href="#search-keys" id="search-keys"></a>

{% code lineNumbers="true" %}

```javascript
db.searchKeys('query') // splitBy is not a param for the searchKeys method
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>query</td><td>Search query</td><td>String</td><td>true</td></tr><tr><td>splitBy</td><td>String to split the Record's content by. For example, \n for lines or " " for spaces. If not present, Dubnium will default to space.</td><td>String</td><td>true</td></tr></tbody></table>

## Get Record from Value (JSON Only) <a href="#from-value" id="from-value"></a>

{% code lineNumbers="true" %}

```javascript
db.getFromValue('key','value',returnType)
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>key</td><td>The key to get from</td><td>String</td><td>true</td></tr><tr><td>value</td><td>The value to get from</td><td>String</td><td>true</td></tr><tr><td>returnType</td><td>Read about it <a href="/pages/GDKFlcVUpNS5ZIpXkKAH#returntype">here</a></td><td>Number</td><td>true</td></tr></tbody></table>

## Check if a Record exists <a href="#exists" id="exists"></a>

{% hint style="info" %}
This will only return `true` or `false`.
{% endhint %}

{% code lineNumbers="true" %}

```javascript
db.has('tag')
```

{% 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>The tag to check for</td><td>String</td><td>true</td></tr></tbody></table>


# Modify

## Modify Record Content (JSON Only) <a href="#content" id="content"></a>

{% code lineNumbers="true" %}

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

{% endcode %}

{% hint style="info" %}
For non-JSON, use [`overwrite()`](#overwrite)
{% endhint %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>key</td><td>The key to change</td><td>String</td><td>true</td></tr><tr><td>value</td><td>The value to set to</td><td>Any</td><td>true</td></tr></tbody></table>

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

{% hint style="warning" %}
Do not use this with JSON records.
{% endhint %}

{% code lineNumbers="true" %}

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

{% endcode %}

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

## Change the length of a Record <a href="#length" id="length"></a>

{% code lineNumbers="true" %}

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

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

{% code lineNumbers="true" %}

```javascript
db.get('tag').overwrite(content)
```

{% 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>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>

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

{% code lineNumbers="true" %}

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

{% endcode %}

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

## Overwrite Content from another Record <a href="#syncwith" id="syncwith"></a>

{% code lineNumbers="true" %}

```javascript
db.get('tag').syncWith('_tag')
```

{% 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>The tag of the Record you want to get the content from.</td><td>String</td><td>true</td></tr></tbody></table>


# Templates

An easy way to keep your JSON records similar!

## Make a new Template <a href="#new" id="new"></a>

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

```javascript
const { Dubnium, Template } = require('dubnium') // require('dubnium') is an alias of require('dubnium').Dubnium
const template = new Template({
id:"",
name:"",
password:""
})
```

{% endcode %}
{% endtab %}

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

```javascript
import { Dubnium, Template } from 'dubnium'
const template = new Dubnium.Template({
id:"",
name:"",
password:""
})
```

{% 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>template</td><td>The object to base the new Template on.</td><td>Object</td><td>true</td></tr></tbody></table>

## Use Template <a href="#use" id="use"></a>

{% code lineNumbers="true" %}

```javascript
database.create('tag', template.use('123456',"John","password"))
```

{% endcode %}

The parameters of this function are what will be set to the value of the keys in order.

**Example**: the parameter`John` will be the value of `name`since they are both in the second position.

## Full code example <a href="#example" id="example"></a>

{% code lineNumbers="true" %}

```javascript
const { Dubnium, Template } = require('dubnium')
// import { Dubnium, Template } from 'dubnium' // for ESM
const database = new Dubnium('./db','json' /* Templates are JSON only */) // Initialize a database

const template = new Template({ // Make a new Template
id:"",
name:"",
password:""
})

database.create('tag', template.use('123456',"John","password")) // Create a Record based on the Template
```

{% endcode %}


# CLI

Run Dubnium functions from your command-line!

## Install

Dubnium CLI comes with all v2 versions

### Install in your project

```bash
npm i dubnium@latest
```

### Install globally

```bash
sudo npm i dubnium@latest -g
```

## Use

If you installed it [globally](#install-globally)

```bash
dubnium <command>
```

If you installed it [in your project](#install-in-your-project)

```bash
npx dubnium <command>
```

### Commands

Commands are **similar** to the API. If you want to call a function on a Record, do **not** put `get().func()`. Instead, make the command just `func` and put the Record's tag as the first arg when prompted.

### Example

![](/files/GPi9ilO2XHRwf6BMak1k)

The CLI will ask for a few values, and then the method will be run and the return value is logged to the console.

## Invoke Programmatically

{% hint style="warning" %}
Make sure the command is present when you run the file.

```bash
node index.js <command>
```

{% endhint %}

{% code lineNumbers="true" %}

```javascript
require("dubnium/cli")
```

{% endcode %}


# Events

Dubnium uses the built-in Events module to send messages when something happens!

| Event         | Callback Arguments              | About                                                                               |
| ------------- | ------------------------------- | ----------------------------------------------------------------------------------- |
| start         | Directory path & File extension | Fires when Dubnium is initialized.                                                  |
| create        | Tag & content                   | Fires when a Record is created.                                                     |
| delete        | Tag & content                   | Fires when a Record is deleted.                                                     |
| overwrite     | Tag, old content, & new content | Fires when a Record is overwritten.                                                 |
| change        | Tag, value's key & new value    | Fires when a Record's value changes.                                                |
| retagged      | Old & new tag                   | Fires when a Record's tag changes.                                                  |
| wipe          | Directory path                  | Fires when the database is wiped.                                                   |
| close         | Directory path                  | Fires when the database is closed.                                                  |
| delete\_old   | Time (in ms)                    | Fires when `deleteOld` is called. (Will also fire `delete` for any Records deleted) |
| dir           | Directroy path                  | Fires when the directory is created.                                                |
| move          | Tag, old & new directory        | Fires when a Record is moved.                                                       |
| clone         | Tag, old & new directory        | Fires when a Record is cloned.                                                      |
| symlink       | Tag & Path to symlink           | Fires when a Symlink is created.                                                    |
| synced        | Tag & tag of synced with        | Fires when `syncWith` is called.                                                    |
| end           |                                 | Fires when the [`end()`](/2/miscellaneous#end) is called.                           |
| delete\_large | max bytes                       | Fires when [`deleteLarge()`](/2/manage#delete-large-records) is called.             |
| append        | tag, content                    | Fires when content is appended                                                      |
| truncate      | tag, length                     | Fires when a Record is truncated.                                                   |
| other         | function name, arguments        | Fires when [`other()`](/2/miscellaneous#other-1) is called                          |
| custom        | callback                        | Fires when [`custom()`](/2/miscellaneous#custom) is called                          |

### Example

```javascript
db.on('create', (tag, content) => { console.log(`${tag} was created!`) })
```


# Plugins

{% hint style="danger" %}
Make sure you trust the plugin as they have access to your database. Read [below](#access) on a way around this.&#x20;
{% endhint %}

### 1. Create a file with the plugins you wish to use

{% code title="my\_plugins.js" lineNumbers="true" %}

```javascript
module.exports = {
    package_example: require("dubnium-test-pkg"),
    function_example: () => { console.log("Hello, world") },
}
```

{% endcode %}

### 2. Load the file

{% hint style="warning" %}
You must run the `loadFromFile()` method before the plugin can be used.
{% endhint %}

{% code title="update\_plugins.js" lineNumbers="true" %}

```javascript
const { PluginManager } = require("dubnium")
PluginManager.loadFromFile('./path/to/my_plugins.js')
```

{% endcode %}

Be sure to run this! You can check if the plugin is registered by checking `PluginManager.activePlugins`. If you updated Dubnium, the plugins may have been reset.

### 3. Use the Plugin

Allow access to **all** data

{% code title="index.js" lineNumbers="true" %}

```javascript
const { Dubnium } = require("dubnium")
const db = new Dubnium('./test_db','json')
db.usePlugin("name")
```

{% endcode %}

### Customize Plugin's access <a href="#access" id="access"></a>

If you do not want to give access to your data through Dubnium, you can also access the `plugins` property.

{% code title="index.js" lineNumbers="true" %}

```javascript
const { Dubnium } = require("dubnium")
const db = new Dubnium('./test_db','json')
db.plugins.name(database, record)
```

{% endcode %}

{% hint style="info" %}
Plugins may ask for database & record (calling the `usePlugin` method automatically passes them both, if possible). You can set either to `null` if you do not wish to give access.
{% endhint %}


# Create

If you want to create a Plugin to publish on NPM, copy the code below and put the source in the exported method.

{% hint style="info" %}
Write your plugins in Commonjs to allow either Commonjs or ESM support!
{% endhint %}

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

```javascript
module.exports = (database, record) => {
// database & record can be null, depending on how the user calls the plugin. Be sure to be able to handle that!
// Plugin source here
}
```

{% endcode %}


# Miscellaneous

## Directory

### Change <a href="#change-dir" id="change-dir"></a>

{% code lineNumbers="true" %}

```javascript
db.dirPath = './new/dir'
```

{% endcode %}

### Make <a href="#make-dir" id="make-dir"></a>

{% code lineNumbers="true" %}

```javascript
db.dir()
```

{% endcode %}

### Get path <a href="#get-dir" id="get-dir"></a>

{% code lineNumbers="true" %}

```
db.dirPath
```

{% endcode %}

### Iterate

```javascript
db.iterate(filepath => {})
```

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>callback</td><td>Callback</td><td>function</td><td>true</td></tr></tbody></table>

## Create Symlink (alias) to a Record <a href="#create-symlink" id="create-symlink"></a>

{% code lineNumbers="true" %}

```javascript
db.get('tag').createSymlink('./path/to/symlink') 
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>dirPath</td><td>Path to a directory where the symlink will be created</td><td>String, filepath</td><td>true</td></tr></tbody></table>

## Get Record's Stats <a href="#get-stats" id="get-stats"></a>

{% code lineNumbers="true" %}

```javascript
db.get('tag').stats
```

{% endcode %}

No parameters

## Content to String & JSON

{% code lineNumbers="true" %}

```javascript
db.get('tag').toString() // returns content as string
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
db.get('tag').toJSON() // returns content as an object, if possible
```

{% endcode %}

No parameters

## End

If you want to *end* a string of methods, you can with `.end()`. It emits the [`end`](/2/events) event and no methods can be added after it. **Note: this is not required.**

{% code lineNumbers="true" %}

```javascript
db.get("tag").overwrite(content).end()
```

{% endcode %}

No parameters

## Exit&#x20;

If you wish to exit the Record editor API, call the `exit()` method and it will return the class.

{% code lineNumbers="true" %}

```javascript
db.get('tag').overwrite(content).exit().//any_class_function
```

{% endcode %}

No parameters

## Something missing? <a href="#other" id="other"></a>

We have a `other()` method that can run any `fs` method on the Record or the `custom()` method to run a custom function without leaving the Record Editor API.

### Other

{% code lineNumbers="true" %}

```javascript
db.get('tag').other('methodName', ...method_args)
```

{% endcode %}

#### Get the return value <a href="#other-return-value" id="other-return-value"></a>

{% code lineNumbers="true" %}

```javascript
db.get('tag').other('methodName', ...method_args).returns
```

{% endcode %}

### Custom

{% code lineNumbers="true" %}

```javascript
db.get('tag').custom((record, record_path) => {
//do anything here
})
```

{% endcode %}

{% code lineNumbers="true" %}

```javascript
db.custom((dubnium, dir_path) => {
//do anything here
})
```

{% endcode %}

### Plugins

{% content-ref url="/pages/bDJ47880MHThrXY6QhDf" %}
[Plugins](/2/plugins)
{% endcontent-ref %}

### Run bash command in the directory <a href="#bash" id="bash"></a>

{% code lineNumbers="true" %}

```javascript
db.bash('command', (error, stdout) => {})
```

{% endcode %}

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>command</td><td>The command (include arguments)</td><td>string</td><td>true</td></tr><tr><td>callback</td><td>Callback</td><td>function</td><td>true</td></tr></tbody></table>

#### Or if you wish to have it added to the API, [tell us](https://github.com/coolstone-tech/dubnium/discussions/new?category=feature-requests\&labels=enhancement)!

## returnType

### About <a href="#returntype-about" id="returntype-about"></a>

Some functions have the `returnType` parameter. The values accepted are `1` and `2`.&#x20;

### 1 <a href="#returntype-1" id="returntype-1"></a>

Return as **JSON**.

### **2** <a href="#returntype-2" id="returntype-2"></a>

Return as an **Array**.

{% code lineNumbers="true" %}

```javascript
db.getAll(1) // will return all the records as an {JSON: 'object'}
db.getAll(2) // will return all the records as an [Array]
```

{% endcode %}


# Update Log

Date format is MM/DD/YYYY

## Get the latest version <a href="#get" id="get"></a>

```bash
npm i dubnium@latest
```

## Version 2 Update History <a href="#header" id="header"></a>

### v2.3.1 (09/25/2022)

* Added name property
* Added [`bash()`](/2/miscellaneous#bash) method
* Added [`iterate()`](/2/miscellaneous#iterate) method
* Fixed [config file issue](https://github.com/coolstone-tech/dubnium/issues/7)
* Some functions will now work with other file types in the dir
* Removed `record.data` & `db.exists()` (use `record.content` & `db.has()` respectively)
* Reworked [plugins](/2/plugins)
* Added `useConfig` param when initializing
* Some internal functions are now exported (fullPath, searchArray, iterateDir)
* Other small changes & improvements

### v2.3.0 (09/03/2022)

* Added [plugins](/2/plugins)
* Added [`realpath`](/2/get#path) property
* Renamed `data` to `content`
* Added [`Record()`](/2/manage#create) method
* Config file
* Removed `watch()`/`unwatch()`, in favor of [events](/2/events)
* `exists()` is now [`has()`](/2/get#exists)
* Other small changes and fixes, including removing random callback params

Read all the changes [here](https://github.com/coolstone-tech/dubnium/commit/f02fa5a5ef70e73426ebbd9327a20587a9359a60)

### v2.2.3 (08/11/2022)

* Fixed [`db.get(...).custom()` issue](https://github.com/coolstone-tech/dubnium/issues/4)
* Fixed [`Template.use()` issue](https://github.com/coolstone-tech/dubnium/issues/5)
* Removed `size` property&#x20;
* Changed [`stats()`](/2/miscellaneous#get-stats) to a property
* More size options for [`deleteLarge()`](/2/manage#delete-large-records)
* Deprecated `watch()` / `unwatch()`
* Other small improvements

### v2.2.2 (08/08/2022)

* Fixed [`other()` issue](https://github.com/coolstone-tech/dubnium/issues/2)
* [Added `custom()` ](/2/miscellaneous#other-1)to run a custom function without leaving the Record Editor API.
* New events

### v2.2.1 (07/30/2022) <a href="#v2.2.1" id="v2.2.1"></a>

* Fixed [`setValue` issue](https://github.com/coolstone-tech/dubnium/issues/1)
* `locateRecord()` is now `find()`&#x20;
* Bug fixes & small improvements&#x20;
* New events
* [Added `other()` ](/2/miscellaneous#other-1)to run any `fs` method on the Record

### v2.2.0 (07/28/2022) <a href="#v2.2.0" id="v2.2.0"></a>

* Removed index.mjs (index.js can be used by ESM & Commonjs)
* `options` param for [`create()`](/2/manage#create) which is passed into `writeFile` (optional)
* [`deleteLarge()`](/2/manage#delete-large-records) will delete Records larger than the specified size (in bytes, for now)&#x20;
* &#x20;[`exit()`](/2/miscellaneous#exit) will return to the Dubnium class.
* [Added `truncate()`](/2/modify#length) to shorten the Record
* [Added `append()`](/2/modify#append) to append data to the Record
* More [search options](/2/get#search-content)
* `size` property for Records.
* Other small improvements & bug fixes

### v2.1.0 (07/26/2022) <a href="#v2.1.0" id="v2.1.0"></a>

* &#x20;Added index.mjs.

### v2.0.1 (07/24/2022) <a href="#v2.0.1" id="v2.0.1"></a>

* Bug fixes
* More methods can be called after [`wipe`](/2/manage#wipe) and [`close`](/2/manage#close)
* `template.new()` is now [`template.use()`](/2/templates#use)
* Redesigned docs

### v2.0.0 (07/16/2022) <a href="#v2.0.0" id="v2.0.0"></a>

* New API style
* New methods:\
  [`syncWith`](/2/modify#syncwith), [`stats`](/2/miscellaneous#get-stats), `watch`/`unwatch`, [`createSymlink`](/2/miscellaneous#create-symlink), & more
* [Templates](/2/templates)
* Bug fixes
* Other small improvements
* [Github repository](https://github.com/coolstone-tech/dubnium)
* Short descriptions in supported IDEs

![](/files/a5X0APlTlJxwFrlCdfXz)


# Install

{% hint style="info" %}
Dubnium is only available through NPM.
{% endhint %}

### Install via NPM

```bash
npm i dubnium@1.4.1
```


# Quick Start

We recommend you read the full docs, but this will get you started with the basics.

## Install

```bash
npm i dubnium
```

## Initialize

{% hint style="info" %}
You can initialize as many databases as you want
{% endhint %}

```javascript
const db = new (require("dubnium"))("./folder",'custom file extension')
/*db.dir() // if you want Dubnium to create a folder for you*/
```

## Make your first Record

```javascript
db.create('tag', data)
```

## Delete a Record

```javascript
db.delete('tag')
```

## Modify a Record

{% tabs %}
{% tab title="Data (JSON only)" %}

```javascript
db.setValue("tag","key","new value")
```

For non-JSON, use [`db.overwrite()`](/1/reference/api/modify#overwrite-record-content)
{% endtab %}

{% tab title="Tag" %}

```javascript
db.setTag("old_tag","new_tag")
```

{% endtab %}
{% endtabs %}

## Get Record

{% tabs %}
{% tab title="Get one" %}

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

```javascript
db.getFromValue('key','value',onlyFirst)
```

{% endtab %}

{% tab title="Get all" %}

```javascript
db.getAll(returnType)
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
`getFromValue` is JSON only
{% endhint %}

### Check out our full docs for more in-depth explanations and code


# API

{% hint style="info" %}

### These docs are up-to-date

Make sure you download the latest version (**1.4.1**)
{% endhint %}

Get into the specifics of the API by checking out our complete documentation.


# Initialize

### Expanded method

```javascript
const DataManager = require('dubnium')
const db = new DataManager('dirPath','ext')
/*db.dir() // if you want Dubnium to create a folder for you*/
```

### One-line method

```javascript
const db = new (require("dubnium"))("./folder")
/*db.dir() // if you want Dubnium to create a folder for you*/
```

{% hint style="info" %}
You can initialize as many databases as you want
{% endhint %}

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>dirPath</td><td>The path to the directory to store Records.</td><td>String</td><td>true</td></tr><tr><td>ext</td><td>Custom file extension (Default: <code>json</code>) </td><td>String</td><td>false</td></tr></tbody></table>


# Create and Delete

## Create Record

Create a new Record.

```javascript
db.create('tag',data)
```

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>tag</td><td>The new Record's tag</td><td>String</td><td>true</td></tr><tr><td>data</td><td>The data to save</td><td>Any (match the chosen file extension)</td><td>true</td></tr></tbody></table>

## Delete Record

Delete a record, found by it's tag.

```javascript
db.delete('tag')
```

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>tag</td><td>The tag of the Record to delete</td><td>String</td><td>true</td></tr></tbody></table>

### Delete Old Records

Will delete Records older than the time provided.

```javascript
db.deleteMany.byAge({ time: { ms:5, seconds:5, minutes:5, hours:5, days:0} })
```

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>time.ms</td><td>Milliseconds</td><td>Number</td><td>false</td></tr><tr><td>time.seconds</td><td>Seconds</td><td>Number</td><td>false</td></tr><tr><td>time.minutes</td><td>Minutes</td><td>Number</td><td>false</td></tr><tr><td>time.hour</td><td>Hours</td><td>Number</td><td>false</td></tr><tr><td>time.days</td><td>Days</td><td>Number</td><td>false</td></tr></tbody></table>


# Get

## Get Record From Tag

Get a Record from it's tag.

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

### Parameters

<table><thead><tr><th>Name</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></tbody></table>

## Get All Records

```javascript
db.getAll(returnType)
```

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>returnType</td><td>Read about it <a href="/pages/KGaIfB7GtxhYbInhTeGt">here</a></td><td>Number</td><td>true</td></tr></tbody></table>

## Fuzzy Search Tags

```javascript
db.searchTags('term',returnType)
```

Fuzzy search made possible by Fuzzy (<https://www.npmjs.com/package/fuzzy>)

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>term</td><td>The search term</td><td>String</td><td>true</td></tr><tr><td>returnType</td><td>Read about it <a href="/pages/KGaIfB7GtxhYbInhTeGt">here</a></td><td>Number</td><td>true</td></tr></tbody></table>

## Get Record from Value (JSON Only)

```javascript
db.getFromValue('key','value',onlyFirst)
```

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox"></th></tr></thead><tbody><tr><td>key</td><td>The key to get from</td><td>String</td><td>true</td></tr><tr><td>value</td><td>The value to get from</td><td>String</td><td>true</td></tr><tr><td>onlyFirst</td><td>Return only the first found Record</td><td>Boolean</td><td>false</td></tr></tbody></table>

## Check if a Record exists

Check if a record exists.

{% hint style="warning" %}
This will only return `true` or `false`.
{% endhint %}

```javascript
db.exists('tag')
```

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>tag</td><td>The tag to check for</td><td>String</td><td>true</td></tr></tbody></table>


# Modify

## Modify Record Content (JSON Only)

Change the Record's key's value to something.

```javascript
db.setValue('tag','key','value')
```

### Parameters

<table><thead><tr><th>Name</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>key</td><td>The key to change</td><td>String</td><td>true</td></tr><tr><td>value</td><td>The value to set to</td><td>String</td><td>true</td></tr></tbody></table>

## Overwrite Record Content

Overwrite a Record found by it's tag.

```javascript
db.overwrite('tag',data)
```

### Parameters

<table><thead><tr><th>Name</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>data</td><td>The data to overwrite with</td><td>Any (must match file extension)</td><td>true</td></tr></tbody></table>

## Modify Record's tag

Change a Record's tag found by its current tag.

```javascript
db.setTag('old','new')
```

### Parameters

<table><thead><tr><th>Name</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>


# Other

## Close

Delete **all** records & the directory

```javascript
db.deleteMany.close()
```

### Parameters

None

## Wipe

Delete **all** records & *preserve* the directory

```javascript
db.deleteMany.wipe()
```

### Parameters

None

## Get path to Record

```javascript
db.locateRecord('tag')
```

### Parameters

<table><thead><tr><th>Name</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>tag</td><td>The tag to locate</td><td>String</td><td>true</td></tr></tbody></table>

## Change directory

```javascript
db.folderPath = './new/dir'
```

### Parameters

N/A

## Make directory

```javascript
db.dir()
```

### Parameters

None

## Get directory

```
db.folderPath
```

### Parameters

N/A


# CLI

```bash
[npx] dubnium <command> <dir> <...args>
```


# Install CLI

Dubnium CLI comes with Dubnium v1.3.0+

### Install in your project

```bash
npm i dubnium@latest
```

### Install globally

```bash
sudo npm i dubnium@latest -g
```


# CLI Use

How you installed the CLI depends on how you can use it.

If you installed it [globally](/1/reference/cli/install-cli#install-globally)

```bash
dubnium <command> <dir> <...args>
```

If you installed it [in your project](/1/reference/cli/install-cli#install-in-your-project)

```bash
npx dubnium <command> <dir> <...args>
```


# CLI Commands

### Command list

All commands are identical to the API.

{% hint style="warning" %}
While commands are automatically synced **with the API version you downloaded**, it is recommended that you update Dubnium to get the newest commands & API.
{% endhint %}

### Example

```bash
dubnium get ./data record
```

### Breakdown

<table data-header-hidden><thead><tr><th>Part</th><th>About</th><th data-hidden></th></tr></thead><tbody><tr><td>dubnium</td><td>Command prefix</td><td></td></tr><tr><td>get</td><td>The API method to call</td><td></td></tr><tr><td>./data</td><td>The directory of Records</td><td></td></tr><tr><td>record</td><td>The API method's argument</td><td></td></tr></tbody></table>


# Events

### Example

```javascript
db.on('create', (tag, data) => { console.log(`${tag} was created!`) })
```

### Event List

| Event Name | Callback Arguments              | About                                |
| ---------- | ------------------------------- | ------------------------------------ |
| start      | Directory path & File extension | Fires when Dubnium is initialized.   |
| create     | Tag & data                      | Fires when a Record is created.      |
| delete     | Tag & data                      | Fires when a Record is deleted.      |
| overwrite  | Tag, old data, & new data       | Fires when a Record is overwritten.  |
| change     | Tag, value's key & new value    | Fires when a Record's value changes. |
| retagged   | Old & new tag                   | Fires when a Record's tag changes.   |
| wipe       | Directory path                  | Fires when the database is wiped.    |
| close      | Directory path                  | Fires when the database is closed.   |
| dir        | Directroy path                  | Fires when the directory is created. |
| move       | Tag, old & new directory        | Fires when a Record is moved.        |
| clone      | Tag, old & new directory        | Fires when a Record is cloned.       |


# returnType

### About

Some functions have the `returnType` parameter. The values accepted are `1` and `2`.&#x20;

### 1

1 returns the data as **JSON**.

### **2**

2 returns the data as an **Array**.

### Example

```javascript
db.getAll(1) // will return all the records as an {JSON: 'object'}
db.getAll(2) // will return all the records as an [Array]
```


# License

## MIT License

Copyright 2022 CoolStone Technologies

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

***


# Update Log

Date format is MM/DD/YYYY

### v1.4.1 (07/13/2022)

* Fixed `overwrite`
* Events won't emit without running the function. (EX: `dir` won't emit if the directory already exists)

### v1.4.0 (07/10/2022)

* Dubnium now has **0** dependencies!
* Bug fixes

### v1.3.0 (06/11/2022)

* [CLI](/1/reference/cli)

### v1.2.0 (06/09/2022)

* [Events](/1/reference/events)
* Bug fixes

### v1.1.0 (05/29/2022)

* Update log
* More options for the [`byAge`](https://db.coolstone.dev/reference/api/create-and-delete) method
* Custom file types
* Bug fixes

### Get the latest version

```bash
npm i dubnium@latest
```

### Archive

[v0](https://db.coolstone.dev/0/)


# Install

{% hint style="info" %}
Dubnium is only available through NPM.
{% endhint %}

### Install via NPM

{% tabs %}
{% tab title="ES6" %}

```bash
npm i dubnium@0.0.6 # ESM only
```

{% endtab %}
{% endtabs %}


# Quick Start

## Install the library

{% tabs %}
{% tab title="NPM" %}

```bash
# Install via NPM
npm i dubnium@0.0.6
```

{% endtab %}
{% endtabs %}

## Make your first Record

```javascript
import {Record} from 'dubnium'
new Record("tag_here",{
"data":"here"
})
```

## Delete a Record

```javascript
import {deleteByTag} from 'dubnium'
deleteByTag("tag_here")
```

## Modify a Record

{% tabs %}
{% tab title="Data" %}

```javascript
import {modifyRecordValueByTag} from 'dubnium'
modifyRecordValueByTag("tag","key","new value")
```

{% endtab %}

{% tab title="Tag" %}

```javascript
import {modifyTag} from 'dubnium'
modifyTag("old_tag","new_tag")
```

{% endtab %}
{% endtabs %}

### Check out our full docs for more in-depth explanations and code


# API

Get into the specifics of the API by checking out our complete documentation.


# Create and Delete Records

## Create Record

Create a new Record.

```javascript
import {Record} from 'dubnium'
new Record("tag",{"data":"here"})
```

## Delete Record

Delete a record, found by it's tag.

```javascript
import {deleteByTag} from 'dubnium'
deleteByTag("tag_here")
```


# Modify Records

## Modify Record Content

Change the Record's key's value to something.

```javascript
import { modifyRecordValueByTag } from 'dubnium'
modifyRecordValueByTag("tag", "key", "value")
```

## Overwrite Record Content

Overwrite a Record found by it's tag.

```javascript
import { overwriteByTag } from 'dubnium'
overwriteByTag("tag",{"data":"here"})
```

## Modify Record's tag

Change a Record's tag found by its current tag.

```javascript
import { modifyTag } from 'dubnium'
modifyTag("old_tag","new_tag")
```


# Get Records

## Get Record From Tag

Get a Record from it's tag.

```javascript
import {getRecordFromTag} from 'dubnium'
getRecordFromTag("tag")
```

## Get All Records

```javascript
import {getAllRecords} from 'dubnium'
getAllRecords()
```

## Fuzzy Search Records

{% content-ref url="/pages/nAlh07Qp5tFrRCZMxeZG" %}
[Fuzzy Search Records](/0/reference/api/fuzzy-search-records)
{% endcontent-ref %}

## Get Record from Value

```javascript
import { getRecordFromValue } from 'dubnium'
getRecordFromValue()
```

## Check if a Record exists

Check if a record exists.

{% hint style="warning" %}
This will only return `true` or `false`.
{% endhint %}

```javascript
import ( doesRecordExistByTag } from 'dubnium'
doesRecordExistByTag("tag_here")
```


# Fuzzy Search Records

## Fuzzy Search By Tag

Fuzzy search all records' tags.

```javascript
import { fuzzySearchByTag } from 'dubnium'
fuzzySearchByTag("tag")
```

Fuzzy search made possible by Fuzzy (<https://www.npmjs.com/package/fuzzy>)


# Other

### Open Record directory in your OS' native file browser

```javascript
import {openRecordDir} from 'dubnium'
openRecordDir()
```

### Open any directory in your OS' native file browser

```javascript
import {openDir} from 'dubnium'
openDir("/path/to/dir")
```


# returnType

### About

Some functions have the returnType parameter. The values accepted are `1` and `2`.&#x20;

### 1

1 returns the data as **JSON**.

### **2**

2 returns the data as an **Array**.

### Example

```javascript
getAllRecords(1) // will return all the records as an {JSON: 'object'}
getAllRecords(2) // will return all the records as an [Array]
```


# License

## MIT License

Copyright 2021 CoolStone Technologies

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

***


