---
title: Databases
project: Flow
version: 11.1
section: components
language: en
license: MIT
url: https://totaljs.es/docs/flow/11-1/components/databases/
updated: 2026-11-20T06:50:57.962Z
---

# Databases

> Components that read and write data in databases.

Components that read and write data in databases. This page holds the catalogue group **Databases**.

Each entry lists the inputs and outputs of the component, its main settings and the text of its readme. To add a component to a FlowStream, see [Download components](/flow/11-1/guides/download-components/).

## API

### influxdb.html · version 1

Type: `component`

Writes data to InfluxDB or runs a Flux query.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | no |  | Server url. |
| `token` | `String` | no |  | Token. |
| `org` | `String` | no |  | Organization. |
| `bucket` | `String` | no |  | Bucket. |
| `api` | `String` | no |  | Action. One of: `write` (Write data), `query` (Execute a Flux query). |
| `fields` | `String` | no |  | Fields. |
| `tags` | `String` | no |  | Tags. |

**Inputs:** `input` (Input).  
**Outputs:** `output` (Output).

Flow installs the npm package `@influxdata/influxdb-client` when you add the component.

**Input**

Expected data for "Write data":

```js
{
    measurement: '<measurement-name>',
	fields: {
        fieldname: <fieldvalue>,
    },
    tags: {
        tagname: '<tagvalue>'
    }
}
```

Expected data for "Execute a Flux query":

```js
{
    query: 'from(bucket: "Some Bucket") |> range(start: -1h)'
}
```

### localstorage.html · version 1

Type: `component`

Stores data for a short time and reads it back.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `savekey` | `String` | no | `id` | Save key. |
| `readkey` | `String` | no | `id` | Read key. |
| `path` | `String` | no |  | Where to save data? |
| `remove` | `Boolean` | no | `true` | Remove the item after reading. |
| `expire` | `String` | no | `1 hour` | Expiration. |

**Inputs:** `save` (Save), `read` (Read).  
**Outputs:** `output` (Output), `error` (Error).

A small and simple persistent storage component is provided by this component. Data can be stored for a short period of time and read when needed.

### mongodb-insert.html · version 1

Type: `component`

Inserts documents into MongoDB.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | no |  | Connection name. |
| `connection` | `String` | no |  | Connection string (without the database name). |

**Inputs:** `input` (Input).  
**Outputs:** `output` (Output).

Flow installs the npm package `mongodb@4.0.0` when you add the component.

**Input**

Example

```javascript
{
    database: 'database-name',
    collection: 'collection-name',
	data: { ... },  // data to insert, object for `insertOne` and an array of objects for `insertMany`
	options: { ... }// insert options as passed to `insertOne(data, options)` or `insertMany(data, options)`
}
```

### mongodb-query.html · version 2

Type: `component`

Runs queries on MongoDB.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `fn` | `String` | no | `return query.find();` | Query editor. |
| `name` | `String` | no |  | Connection name. |
| `connection` | `String` | no |  | Connection string (without the database name). |

**Inputs:** `input` (Input).  
**Outputs:** `output` (Output).

Flow installs the npm packages `mongodb@4.0.0`, `mquery` when you add the component.

Uses mquery under the hood. Here is the [documentation](https://www.npmjs.com/package/mquery)

**Input**

Example

```javascript
{
    database: 'database-name',
    collection: 'collection-name',
	data: <any> // this prop will be passed into the query function
}
```

**Query editor**

```js
// query; mquery instance
// data; data from the incomming object

return query.find(); // return all documents
```

**Important**

In the `.select()` you cannot use inclusion and exclusion together.
This is invalid: `.select('firstname -lastname')`
Valid exclusion: `.select('-lastname')` or `.select('-email -lastname')` etc.
Valid inclusion: `.select('name email')` or `.select('email lastname')` etc.

### mysql.html · version 2

Type: `component`

Runs SQL queries on a MySQL database.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `connection` | `String` | no |  | Connection string. |

**Inputs:** `input` (Input).  
**Outputs:** `output` (Output).

Flow installs the npm package `mysql2` when you add the component.

**Input**

Expected data:

```javascript
{
	query: 'SELECT * FROM tblname;'
}
```

### nosql.html · version 1

Type: `component`

Inserts, reads, queries, updates and removes documents in the Total.js NoSQL database.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `collection` | `String` | no |  | DB collection(table) name. |
| `method` | `String` | no |  | Method. One of: `insert` (Insert), `update` (Update), `read` (Read), `query` (Query), `remove` (Remove). |
| `addid` | `String` | no |  | Add unique ID to `id` property of data before insert. |
| `upsert` | `String` | no |  | Insert document if it doesn't exist. |
| `upsertid` | `String` | no |  | Add unique ID to `id` property of data before insert (only if it doesn't exist). |

**Inputs:** `input` (Input).  
**Outputs:** `output` (Output).

**Outputs**

- response from nosql engine

**Settings**

- collection: (optional) if not set, incomming data object must have a 'collection' property set
- method: (optional) if not set, incomming data object must have a 'method' property set

**Input**

```javascript
{
	collection: 'users', // optional, will override settings value
	method: 'query', // insert|read|query|update|remove - optional, will override settings value
	// for insert, update
	data: { ... },
	// for query, read, update, remove
	filter: [
		['where', 'sensor', 'temp'], // builder.where('sensor', 'temp');
		['limit', 2]                 // builder.limit(2);
	],
	upsert: true // only for update, if set then document will be inserted if it doesn't exist
	addid: true  // only for insert and update, if set then id prop will be automaticaly generated (for update only when upsert is also set)
}
```

**Insert**

- inserts recieved data
- expects data to be an Object
- returns error, success, id

**Read**

- returns first document found
- requires `filter`
- returns error, response

**Update**

- updates document(s)
- expects data to be an Object with all the props to be updated
- requires `filter`
- returns error, response
- if response is 0 then update failed

**Remove**

- removes document
- requires `filter`
- returns error, response
- if response is 0 then remove failed

**Query**

- returns all documents found
- requires `filter`
- returns error, response

### postgresql.html · version 2

Type: `component`

Runs SQL queries on a PostgreSQL database.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `connection` | `String` | no |  | Connection string. |

**Inputs:** `input` (Input).  
**Outputs:** `output` (Output).

Flow installs the npm package `pg` when you add the component.

PostgreSQL

**Input**

Expected data:

```javascript
{
	query: 'SELECT * FROM tblname;'
}
```

Output:

```javascript
{
	command: 'INSERT', // SELECT, etc.
	rows: [], //
	rowCount: 1
}
```

### sqlite3.html · version 2

Type: `component`

Runs queries on an SQLite3 database.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Filename (optional). |

**Inputs:** `input` (Input).  
**Outputs:** `output` (Output), `error` (Error).

Flow installs the npm package `better-sqlite3` when you add the component.

SQLite3 [Documentation](https://github.com/JoshuaWise/better-sqlite3/blob/HEAD/docs/api.md)

```js
{
	// query
	prepare: 'INSERT INTO cats (name, age) VALUES (?, ?)',

	// function name: run, get, all, exec
	fn: 'run',

	// data, optional
	data: ['Joey', 2] // string/number or array

}
```

__Functions:__

- [run](https://github.com/JoshuaWise/better-sqlite3/blob/HEAD/docs/api.md#runbindparameters---object)
- [get](https://github.com/JoshuaWise/better-sqlite3/blob/HEAD/docs/api.md#getbindparameters---row)
- [all](https://github.com/JoshuaWise/better-sqlite3/blob/HEAD/docs/api.md#allbindparameters---array-of-rows)
- [exec](https://github.com/JoshuaWise/better-sqlite3/blob/HEAD/docs/api.md#execstring---this)
